Forum Moderators: coopster
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.
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.