Page 1 of 1

PHP FTP functions - HELP

Posted: Fri Nov 21, 2008 4:50 pm
by dstefani
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I want to end up with a script I can run via a cron job to upload files every night.
So I've been trying to use the samples from the PHP manual in the FTP functions area.

The file uploads, or at least a file with that name shows up on the remote server, but it's always empty!?!?

<sigh>

Thanks,

- D

Here's my code:

Code: Select all

<?php
 
 
$ftp_server = 'ftp.myserver.com';
$ftp_user_name = 'myUser';
$ftp_user_pass = 'myPass';
 
// 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); 
 
// check connection
if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        exit; 
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }
 
$source_file = '/Users/myloaclsite/Sites/myJob/feed/CC27249.txt';
$destination_file = '/tmp/CC27249.txt';
 
// upload the file // ####################################################
//$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII); 
 
// check upload status
if (ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) { 
        echo "<p>FTP upload has failed!</p>";
    } else {
        echo "<p>Uploaded $source_file to $ftp_server as $destination_file</p>";
    }
 
// close the FTP stream 
ftp_close($conn_id); 
 
?>
 

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: PHP FTP functions - HELP

Posted: Fri Nov 21, 2008 5:04 pm
by pickle
Proper syntax highlighting provides some clues.

Re: PHP FTP functions - HELP

Posted: Fri Nov 21, 2008 5:12 pm
by dstefani
sorry about the posting style, I'll get with that.

The quote was messed up when I changed the names, etc.
It's right in my code.

Thanks,

- D