我必须通过 ftp 连接到一台服务器并下载 zip 文件。
这是我尝试过的但没有任何运气:
$url = $server_file = '/expiring_service_auctions.csv.zip';
$target = $local_file = 'godaddy.zip';
$out = 'godaddy.csv';
$ftp_server = 'ftp.godaddy.com'; //'208.109.78.100'
$ftp_user_name = 'auctions';
$ftp_user_pass = ''; //no pass
// 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);
// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");
// output $contents
var_dump($contents);
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);
该怎么办?该怎么办?
当我登录FTP服务器时,它建议使用PASV。在您的登录行后添加此内容:
ftp_pasv($conn_id, true);
服务器可能正在使用不可路由的 IP 进行响应。
您可以在本地计算机上测试它并查看如下日志消息:
227 Entering Passive Mode (10,124,6,21,11,40).
Server sent passive reply with unroutable address 10.124.6.21, using host address instead.
LIST -a
Connecting to <original IP>:2856 ...
桌面客户端将自动更正此问题。
对于 PHP,您需要设置以下选项来忽略错误的 IP。
ftp_set_option($connection, FTP_USEPASVADDRESS)
对于 Flysystem 适配器,这是“ignorePassiveAddress”选项。