ftp_get失败但未报告错误

问题描述 投票:1回答:1

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

// define variables
$folder_path = "Applications/MAMP/htdocs/infoscreen/PVdata";
$local_file = fopen ("newpv.csv",'w');
$server_file = "[email protected]";

// 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);
php ftp
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.