• Advertisement
Sign in to follow this  

[web] Problem using simple ftp upload

This topic is 4323 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using the following short script to try and upload a file to an ftp server (the script is the example for ftp_fput from php.net). Usually the script executes perfectly and the file is created and filled correctly. However, occasionaly the file is created on the server, but it has a size of zero bytes and no data is in it and the following warning is recieved: Warning: ftp_fput(): Opening BINARY mode data connection for somefile.txt in ... on line 19 The server, username and password are correct, verified by maually logging in with an ftp program. The php version being run is 4.4.2. I have had safe mode turned off on both the server running the php script and the server i am ftping the file too, this seems to have made it work successfully more often.
// Server, username and password settings removed for security

// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');

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

$response = ftp_chdir($conn_id, "httpdocs");

// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
   echo "Successfully uploaded $file\n";
} else {
   echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);

Does anybody have any suggestions, any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Dragoncar
Does anybody have any suggestions, any help would be greatly appreciated.

Perhaps a firewall, router, or NAT might be blocking the data transfer port, maybe you should use PASV mode?
Perhaps you filled your disk quotas?
Perhaps it has bad file/directory/other permissions?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement