ftp_get失败但未报告错误

时间:2017-12-06 10:45:52

标签: php ftp

我无法将文件从FTP服务器下载到本地计算机。我继续从ftp_get

得到错误
// define variables
$folder_path = "Applications/MAMP/htdocs/infoscreen/PVdata";
$local_file = fopen ("newpv.csv",'w');
$server_file = "tlxesb@pv-systems.dk-171206100007";

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// turn passive mode on
ftp_pasv($conn_id, true);

// 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 :(得分:0)

ftp_get将本地路径的路径作为第二个$local_file参数,而不是文件句柄:

$local_file = "newpv.csv";
ftp_get($conn_id, "newpv.csv", $server_file, FTP_BINARY);

或许你想使用ftp_fget,它需要一个句柄:

$handle = fopen("newpv.csv", 'w');
ftp_fget($conn_id, $handle, $server_file, FTP_BINARY)

虽然它只是有意义,但如果你想对文件做更多的事情,否则使用简单的ftp_put

此外,请确保在上传完成后关闭手柄:

fclose($handle);