Re: [PHP] ftp_put and ftp_fput both failing me

2005-01-27 Thread Wayne Zeller
Marek Kilimajer wrote:
30 seconds? This must be your firewall blocking connections from outside 
world. Use ftp_pasv() to turn on passive mode.
That did the trick. Thanks s much!
Wayne
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ftp_put and ftp_fput both failing me

2005-01-27 Thread Wayne Zeller
Marek Kilimajer wrote:
You must use ftp_fput() because you are using open file handle.
Check that tmpfile() did not fail. Then make sure you are in the right 
directory after logging in the ftp server.
That's what I get for trying to put together code for my post during 
attempts to do it several different ways. I ended up posting code that 
was a hybrid of when I tried it using the file name with ftp_put and 
when I used a file handle with ftp_fput.

The exact same code that I posted, but with ftp_fput instead of ftp_put 
gives the same results.

The script takes about 30 seconds to run, and then reports its failure. 
 I've verified that the temp file is being created with the correct 
contents.

Getting this to work is pretty key for a project I'm working on, so if 
there's another way to do it, even if it's a "harder" way, I'm totally 
open to any suggestions.  :)

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


[PHP] ftp_put and ftp_fput both failing me

2005-01-27 Thread Wayne Zeller
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