Forum Moderators: coopster

Message Too Old, No Replies

Error uploading using FTP

         

iceman22

4:17 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



I've written a simple backup script that takes arguments to backup files or directories. After the file or directory is a gzipped encrypted and compressed disk image, it is uploaded to an FTP server.

I've been changing some things every few days but I've noticed cron sending me error mails when I though I hadn't changed the code, I can't say for certain though.

This is the error I am receiving:

Warning: ftp_put(): CWD command successful in /Users/dave/bin/backup.php on line 89
Unable to upload file.

This is the function that does the upload:

function performUpload($ftp, $img_name) {

$conn_id = ftp_connect($ftp['server']);

$login_result = ftp_login($conn_id, $ftp['username'], $ftp['password']);
if ( (!$conn_id) ¦¦ (!login_result) ) {
exit("Unable to connect to FTP server.\n\n");
}
if (!(ftp_chdir($conn_id, $ftp['path'])) ) {
ftp_mkdir($conn_id, $ftp['path']);
ftp_chdir($conn_id, $ftp['path']);
}
if (!(ftp_put($conn_id, $img_name['file'], $img_name['path'], FTP_ASCII)) ) {
exit("Unable to upload file.\n\n");
}

ftp_close($conn_id);

}

The $ftp array simply contains the server, username, password and directory. The $img_name array contains the filename and the fullpath of the local file, for example:
Array
(
[file] => file.txt-backup_05-04-11.dmg.gz
[path] => /tmp/file.txt-backup_05-04-11.dmg.gz
)

If I paste this into the shell (it will do the same thing as entering each line separately), it will upload fine. It will also upload a lot faster than the PHP script would when it was working.

ftp -n <server>
quote USER <username>
quote PASS <password>
cd /backups/
put /tmp/file.txt-backup_05-04-11.dmg.gz file.txt-backup_05-04-11.dmg.gz
quit

I've tried making all kinds of changes but I can't work out why it isn't working, I'm using PHP version 4.3.10 on Mac OS X.

whoisgregg

4:43 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Quick idea: I was running a cron job that was throwing errors like yours and the solution was using the full path to the binaries:

For example, /usr/bin/ftp instead of ftp, worked

I was also running Mac OS X. 10.3.8 Client with the standard PHP install.

iceman22

4:58 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



Where would I change the path PHP uses for FTP?

whoisgregg

7:56 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Having re-read your post a couple times, I realize now I was confused. Your PHP script is executing fine and you should ignore my quick idea. Sorry about that. :(

iceman22

3:32 am on Apr 16, 2005 (gmt 0)

10+ Year Member



Sorry if it was confusing, I was trying to illustrate that I could perform a similar task using the shell.

I tried removing the CWD line of the FTP function and it gave me an error on at the ftp_put() function again.

Warning: ftp_put(): User <user> logged in. in /Users/dave/bin/backup.php on line 93
Unable to upload file.

What it seems to be doing at line 93 is giving an error and outputting the last FTP command, before it was outputting the CWD command, with that removed it's outputting the result of the login.