开发者

ftp_get fails but no error reported by PHP

I trying to get a file from an FTP server using ftp_get from PHP 5.3.3 (linux build). I can login, I can list the files, but the ftp_get command does not download the file.

Here is the code I'm using.

$ftp_use开发者_如何学运维r_name = DBUSER;
$ftp_user_pass = DBUSERPASS;
$ftp_server = HOST;
$local_file = "poutarde.odt";
$server_file = "poutarde.odt";

// set up a connection to ftp server
$conn_id = ftp_connect($ftp_server);

// 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);

The "poutarde.odt" file is at the root of the FTP.

I checked the FTP download from a client (filezilla) and everything works perfectly. However, using ftp_get, I get nothing (except the echo "There was a problem"), no even a PHP error, it just fails.

Thank you for you help.

Reno


ftp_get expects a file handler, not a filename.

$local_file = fopen("poutarde.odt",'w');
//...
if(ftp_get($conn_id, $local_file, $server_file, FTP_BINARY))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜