PDA

View Full Version : PHP FTP functions.....




bigandy
Apr 10, 2007, 01:14 PM
I've got a script that uploads a file, but then, after processing, it needs to FTP it to another server.

The script I've got is as follows. What am I missing, as the php file doesn't actually finish loading if this part of the file is there. :(

$ftp_server = "www.server.net";
$ftp_user_name = "user@server.net";
$ftp_user_pass = "password";
$source_file = "/home/user/public_html/directory/$exefile.ext";
$destination_file = "$exefile.ext";

echo $conn_id = ftp_connect($ftp_server);

echo $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

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";
}

echo $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// close the FTP stream
ftp_close($conn_id);

Help much appreciated :o

edit: the directory should be set by the custom user for this FTP upload script.. but do I need to set that anyway?

also, does it have a limit? is that why it's messing up? can i run FTP from the shell using exec? i know that the linux shell ftp needs user input, can i emulate this? it doesn't work if i do this:

ftp www.server.net user@server.net password send /home/user/public_html/directory/file.ext file.ext exit

because it needs a carriage return between each command sent :(



Winterfell
Apr 21, 2007, 09:38 AM
Can you post the output of the script where it fails? Is there any output?

bigandy
Apr 21, 2007, 01:39 PM
There isn't any output... I'll post what detail I have soon, I'd kinda given up hope on hearing any replies! :o

Winterfell
Apr 21, 2007, 05:07 PM
Try putting error_reporting(E_ALL); at the very top of your PHP script (right after the very first <?php opening tag). That will tell PHP to output everything: errors, warnings, you name it. Maybe that will give us something more to go on. :)