My first attempt at posting this appears to have failed, so I'll try again. My apologies if this is a duplicate...



I can't for the life of me figure out why this won't work. I am downloading a file from a remote host via ftp, processing it and modifying part of it, and then uploading the updated file back to the remote server via ftp.

Everything is working great until it comes time to put the modified file back onto the remote host.

The script successfully logs in, but fails to put the file.

I want the final file to overwrite the original, but it fails even if I give it a new name so as to not overwrite. So overwriting isn't the problem.


Here is the section of code I'm using:


// I'm putting my contents into $myfile: $myfile = 'A bunch of text. (An html file, actually.)';

// Setting up connection parameters:
$ftp_server = 'www.myserver.com';
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$remote_file_name = 'filename.htm';

// Create a tmp file:
$fp = tmpfile();
fwrite($fp, $myfile);
rewind($fp);

// Log into the remote server:
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result)) {
       echo "FTP connection has failed!";
       echo "Attempted connection to $ftp_server for $ftp_user_name";
       exit;
   } else {
       echo "Connected to $ftp_server, for user $ftp_user_name.";
   }
// EVERYTHING WORKS FINE UP TO HERE

// upload the file:
$upload = ftp_put($conn_id, $remote_file_name, $fp, FTP_ASCII); //FAILS!

// check upload status
if (!$upload) {
       echo "FTP upload has failed! $upload"; //THIS IS THE OUTPUT I GET
   } else {
       echo "Uploaded $source_file to $ftp_server as $destination_file";
   }

// close the FTP stream
ftp_close($conn_id);



When I run the program, it returns "Connected to (servername), for user (username).FTP upload has failed!"

Sure enough, when checking on the remote server, the file has not been touched.

I've tried using a file handle and using ftp_fput, but I get the same results.

I'm probably missing something obvious. If anybody sees it, please let me know!

Wayne

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to