【发布时间】:2013-02-26 10:45:00
【问题描述】:
我想通过 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
)
如果您想了解更多信息,请告诉我。
提前致谢,
丹尼斯
【问题讨论】:
-
是的,我已经阅读了这篇文章并想出了发布的代码 n-p。我的问题是这可以在我的测试机上完美运行,但不能在我的服务器上运行。而且我不知道为什么http代码是257(在我的测试机器上代码是226,这是正确的)。
-
如果是共享主机,他们的设置可能会有一些限制。服务器运行的是什么版本?