我想通过 cURL 从 ftp 服务器下载文件。这是我的功能:
function getFile($remotefolder, $remotefile, $localfile) {
$url = "ftp://xxxxx.de/" . $remotefolder . "/" . $remotefile;
$fp = fopen($localfile, "w+");
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($handle, CURLOPT_UPLOAD, 0);
curl_setopt($handle, CURLOPT_FILE, $fp);
curl_setopt($handle, CURLOPT_USERPWD, "<Username>:<Password>");
$result = curl_exec($handle);
$info = curl_getinfo($handle);
curl_close($handle);
fclose($fp);
print_r($info);
}
如果我在我的电脑上执行,一切正常。但是当我在服务器上运行代码时,它给了我以下输出并且文件没有下载:
output server
=============
Array
(
[url] => ftp://xxxx/xxxx/xxx.log.gz
[content_type] =>
[http_code] => 257
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.357453
[namelookup_time] => 0.002011
[connect_time] => 0.011153
[pretransfer_time] => 1.357439
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0
)
如果您请提供更多信息,请告诉我。
提前致谢,
丹尼斯