代码中使用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