Is there any way to get the reason for the failure of ftp_put?

I have an FTP class that has the function of connecting, disconnecting, downloading and uploading files to another ftp server.

I have this function, and I wanted to register the reason for the download failure in a text file, but based on ftp_put documents, this returns false only when an error occurs :

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 cause of the failure for ftp_put ? And what are these reasons? Or is the only error message that I could log is something like a generic message ?:

Error loading file Foo.bar 12:01:01 2015-01-01

+5
source share
1 answer

FTP Functions FTP generates a warning with the last error message returned by the server.

So when this happens:

 > STOR /nonexistingfolder/readme.txt < 550 Filename invalid 

You will receive a warning:

Warning: ftp_put (): file name is invalid in test.php on line 12

No further information is provided. In particular, you cannot activate any FTP session log.


When a local problem occurs (for example, a problem with a missing local file or permissions), you get a warning, as with any other PHP function:

Warning: ftp_put (nonexisting.txt): could not open the stream: there is no such file or directory in test.php on line 12


However, I find the suspicious "Foo.bar H: i: s Ymd". What is "H: i: s Ymd"? Could you pass the date format string through the date function using format literature instead?

+1
source

All Articles