PHP FTP functions - HELP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

PHP FTP functions - HELP

Post 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.
Last edited by dstefani on Fri Nov 21, 2008 5:10 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP FTP functions - HELP

Post by pickle »

Proper syntax highlighting provides some clues.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

Re: PHP FTP functions - HELP

Post 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
Post Reply