I have a FTP class that has function in connecting, disconnecting, uploading and downloading files to the other ftp server.
I have this function and I wanted to log the reason why the upload fails in a text file, but based on the ftp_put docs, it only returns false on failure:
public function upload($remote_file, $file, $mode = FTP_ASCII)
{
if (!ftp_put($this->ftp_connection, $remote_file, $file, $mode))
{
throw new Exception("There was a problem while uploading $file", 1);
}
$this->last_uploaded_file = $file;
return true;
}
Is there any way to get the reason of failure for ftp_put
? And what are those reasons? Or the only error message I could log is something like a generic message?:
Error uploading file Foo.bar 12:01:01 2015-01-01
PHP FTP functions issue a warning with the last error message returned by the server.
So when this happens:
> STOR /nonexistingfolder/readme.txt
< 550 Filename invalid
You get a warning like:
Warning: ftp_put(): Filename invalid in test.php on line 12
There's no more information provided. Particularly you cannot enable any kind of FTP session logging.
When there's a local problem (like a non-existing local file or permissions issue), you get a warning, as with any other PHP function:
Warning: ftp_put(nonexisting.txt): failed to open stream: No such file or directory in test.php on line 12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With