代碼中使用PHP內置的FTP流
// the file your trying to get
$file ="ftp://ftp_user:[email protected]/file.txt";
// get the file
$contents = file_get_contents($file);
代碼下載使用PHP的內置的HTTP流
// the file your trying to get
$file ="http://domain.com/file.txt";
// get the file
$contents = file_get_contents($file);
代碼將文件上傳下載文件(放)文件上遠程FTP
// get the file from LOCAL HARD DRIVE
$contents = file_get_contents('C:/local/path/to/file.txt');
// the file your trying to UPLOAD
$file ="ftp://ftp_user:[email protected]/file.ext";
// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
或結合以上幾點:使用FTP下載,使用FTP上傳
// the file your trying to get
$file ="ftp://ftp_user:[email protected]/file.txt";
// get the file USING FTP
$contents = file_get_contents($file);
// the file your trying to UPLOAD
$file ="ftp://ftp_user:[email protected]/file.ext";
// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
使用下載HTTP,使用FTP上傳
// the file your trying to get
$file ="http://domain-ONE.com/file.txt";
// get the file USING HTTP
$contents = file_get_contents($file);
// the file your trying to UPLOAD
$file ="ftp://ftp_user:[email protected]/file.ext";
// write USING FTP
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
file_put_contents($file, $contents, NULL, $context);
該代碼可以遠程在網絡服務器上的Web服務器在本地使用PHP-CLI或遠程使用跑,本地的,PHP-CLI通過SSH 。
讓我知道你的具體要求,我會調整我的答案
你只是不能(或它是無用的)。你很樂意上傳每個文件。 – n1xx1
你可以簡單地使用Python直接從Web服務器將文件寫入本地磁盤?我非常懷疑它。 – deceze
只需在本地機器上運行該文件! – Philipp