通过ftp与PHP的连接

通过ftp与PHP的连接,php,ftp,Php,Ftp,我必须通过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连接到一台服务器并下载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);

你收到任何错误消息了吗?不知何故,我怀疑godaddy是否会让这个文件位于他们文件系统的根目录中。您确定该文件的源路径正确吗?它可能不仅仅是
/expiring.csv.zip
,更像是
/home/username/expiring.csv.zip
@MarcB直接登录到他们的FTP,它在根目录中。可能是因为
拍卖
用户名。@pmagunia在试图查看我得到的文件时:布尔(False),脚本的其余部分,正在加载,没有任何结果。它工作起来很有魅力,非常感谢您的建议。