繁体   English   中英

用PHP连接ftp

[英]Connection over ftp with PHP

我必须通过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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM