用PHP连接ftp

时间:2013-08-02 20:27:50

标签: 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_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);

怎么办?怎么办?

1 个答案:

答案 0 :(得分:2)

当我登录FTP服务器时,建议使用PASV。在登录行后添加:

ftp_pasv($conn_id, true);