FTP acting up

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
chadillac
Forum Newbie
Posts: 12
Joined: Tue Feb 28, 2006 3:30 pm
Location: Fort Lauderdale

FTP acting up

Post by chadillac »

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.

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); 

?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Remove your @'s and see if you get any error messages. Maybe your host has some of the functions your using disabled?
chadillac
Forum Newbie
Posts: 12
Joined: Tue Feb 28, 2006 3:30 pm
Location: Fort Lauderdale

Post by chadillac »

without the error suppression I still get no errors.

also if I view the source it acts as if it loops through the for loop once and the source generated is just a single set of <p></p>'s


I have been working with my hosting service and they can't figure it out either, they have set world readable folders and looked through my php.ini with out any success.


this is a very fishy problem, is a huge pain in my ..... neck ;)


_____________ EDIT __________________

here is one error message that was generated when running this script, but not derivitives of it I tweaked later on.

Code: Select all

Warning: ftp_pwd(): Can't open data connection. in /home/www/cableorganizer/authclick/test.php on line 26
but it works fine on my local server....
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well this is straight from the manual, so if it doesn't work I am stumped.

Code: Select all

<?php

// 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);

// change directory to public_html
ftp_chdir($conn_id, 'public_html');

// print current directory
echo ftp_pwd($conn_id); // /public_html

// close the connection
ftp_close($conn_id);
?>
chadillac
Forum Newbie
Posts: 12
Joined: Tue Feb 28, 2006 3:30 pm
Location: Fort Lauderdale

Post by chadillac »

essentially thats exactly what I'm doing.

this is what the output SHOULD be when it runs correctly... this is the output I get when I run it locally on my private server (ironically connecting to the flawed server)

Code: Select all

You are in the directory: /home/abccook/www/gm

total 48

-rw-r--r-- 1 515 530 1408 Jan 25 12:55 abc.user.js

-rw-r--r-- 1 515 530 356 Feb 13 14:18 abc2.user.js

-rw-r--r-- 1 515 530 1136 Jan 24 18:40 bio.user.js

-rw-r--r-- 1 515 530 1088 Jan 24 13:25 helloworld.user.js

-rw-r--r-- 1 515 530 3475 Feb 13 13:32 psu.jpg

-rw-r--r-- 1 515 530 1438 Jan 24 17:13 test.user.js
File uploaded OK.

and this is what I get when I put the same exact script on the server and try to run it.

Code: Select all

Warning: ftp_pwd(): PORT command successful. in /home/www/abccook/data/index2.php on line 23
You are in the directory:


Warning: ftp_put(): Can't build data connection: Connection timed out. in /home/www/abccook/data/index2.php on line 31
File upload failed.

Everyone I have shown this to is stumped... no one can figure out why in the world its not working....


I'm convinced it has to be a server setting on my hosting services side, but they claim everything is ship shape.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well it's probably something unrelated yet simple. Perhaps that box can't resolve the NS properly or DNS or something.
chadillac
Forum Newbie
Posts: 12
Joined: Tue Feb 28, 2006 3:30 pm
Location: Fort Lauderdale

Post by chadillac »

figured it out.... apparently on PHP5 passive mode is set as an automatic setting I'm assuming. But since the server was running a little bit of an older version you have to manually trigger pasv mode.

Code: Select all

ftp_pasv($conn, true);

also, let it be known that the server I am uploading to, if using an FTP client, must us forced Active mode.... but if the PHP has to connect the ftp_pasv() settings still have to be set to "true".


strange bug, but its working now...
Post Reply