【发布时间】:2014-01-24 14:15:42
【问题描述】:
<?php
// sample usage
ini_set('max_execution_time', 6000);
ini_set('memory_limit', '-1');
$local_file = '123.jpg';
$server_file = '/animals/pets/dogs/pitbull.jpg';
$ftp_user_name='username';
$ftp_user_pass='password';
$ftp_server='URL';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 60);
ftp_pasv($conn_id, false);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)){
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>
上面的代码没有下载文件。 下载文件可能有什么问题?
【问题讨论】:
-
你得到的输出是什么?
-
您有什么迹象表明存在问题?有错误吗?意外行为?对服务器的请求是什么?服务器的响应是什么?您至少需要进行一些调试。
-
/photos/bigphoto/529/509529_01.jpg是绝对路径,你确定不要使用相对路径 -
你有什么错误吗??
-
正如 Jompper 提到的,使用相对路径而不是绝对路径。如果您的
animals文件夹是您运行脚本的根目录中的一个,请使用$server_file = 'animals/pets/dogs/pitbull.jpg';@BannedfromSO ---绝对路径类似于$server_file = '/var/user/you/public_html/animals/pets/dogs/pitbull.jpg';