Connecting Tech Pros Worldwide Forums | Help | Site Map

FTP with PHP

CyberCog
Guest
 
Posts: n/a
#1: Nov 21 '08
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,

- Cy

Here's my code: <?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/mylocalsite/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);

?>

Closed Thread