且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用curl和php从ftp下载一个文件

更新时间:2023-11-24 09:44:22

我的猜测是你的URL指向一个目录,而不是一个文件。您需要将CURLOPT_URL的完整网址提供给该文件。

My guess is that your URL is pointing towards a directory, not a file. You would need to feed CURLOPT_URL the full URL to the file. Also if you want to download a file you might want to save it somewhere.

工作范例:

$curl = curl_init();
$file = fopen("ls-lR.gz", 'w');
curl_setopt($curl, CURLOPT_URL, "ftp://ftp.sunet.se/ls-lR.gz"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
curl_exec($curl);
curl_close($curl);
fclose($file);