php - Path to network file -
my web server running on 1 server, , data fetching running on server. code try copy remote file , store in local path. remote location is, example, /home/testuser/remotedata.xml. know server ip address , hostname. how can construct path fill in remotepath?
#remotepath path file on network public function __construct() { $this->localpath="currentdata.xml"; $this->remotepath="a remote path"; } #this attempt make copy network file , store locally private function fetchserver() { if (!(file_exists($this->remotepath)) || (time() - filectime($this->remotepath)) >= 1200) return false; else { $success = copy($this->remotepath, $this->localpath); if($success) return true; else return false; } }
thank much!
if you're using http, won't able check creation time. if know small, manageable file, can use file_get_contents:
$fl = @file_get_contents( '<stream>' ); if( !$fl ) return false; // file not exist remotely $ret = @file_put_contents( '<output name>', $fl );// output return $ret && true; //force boolean
if bit larger, can use curl , stream syntax, or can similar did above:
$fl = @fopen( '<stream>' ); if( !$fl ) return false;// file not exist remotely $out = @fopen( '<local file>', 'w'); if( !$out ) return false; while($data = fread($fl)){fwrite($out,$data);} fclose($out); return true;
of course, situations have download file local version , form of checksum see if there difference.
edit
you mentioned timestamp requirement have ssh. if have ssh, might able use sftp (which piggy-backs off of ssh). have used phpseclib several projects and, while not perfect (it in php4 , not tunnel ssh), impressive library nevertheless. @ networking part of manual , (if remember) give more enough you're asking for.
Comments
Post a Comment