FTP acting up
Posted: Mon Mar 20, 2006 2:11 pm
I am currently working on a script that will be triggered by a CRON for FTP upload automation. I set it up initially on my local server running PHP 5 and it worked beautifully. Connected, changed dir., uploaded and renamed files without a hitch. I figured I would have to tweak a few settings referencing directories and stuff as I moved over to the real server. I made the appropriate changes and uploaded the file... and it breaks...
here is the PHP code that should be handling everything, and works fine on my local server, but not on our other server running PHP 4. It does allow me to connect to the server, but it fails to run anything much beyond that. I can get ftp_pwd() and such, but I cannot get a rawlist?
Please give it a look over and explain anything you see that could even remotely be the cause of such strange issues.
here is the PHP code that should be handling everything, and works fine on my local server, but not on our other server running PHP 4. It does allow me to connect to the server, but it fails to run anything much beyond that. I can get ftp_pwd() and such, but I cannot get a rawlist?
Please give it a look over and explain anything you see that could even remotely be the cause of such strange issues.
Code: Select all
<?php
$dateis = date("m-d-y");
$filename = "CableOrganizer_".$dateis."_access2";
$ftpServer = "****";
$ftpUser = "****";
$ftpPass = "****";
set_time_limit(160);
$conn = ftp_connect($ftpServer)
or die("Couldn't connect to FTP server");
$login = ftp_login($conn, $ftpUser, $ftpPass)
or die("Login credentials were rejected");
@ftp_chdir($conn, '/');
$files = ftp_rawlist($conn,'/');
$workingDir = ftp_pwd($conn);
echo "You are in the directory: $workingDir";
for($i = 0;$i < count($files); $i++){
echo "<p>$files[$i]</p>";
}
$putFile = ftp_put($conn, "$filename.gz", "cableorganizer-access-log.gz", FTP_BINARY);
if($putFile)
echo "File uploaded OK.";
else
echo "File upload failed.";
ftp_quit($conn);
?>