PHP ftp_mdtm() not support by server

ftpPHP

Are there any other solutions but ftp_mdtm() for getting file modification date/time using FTP functions?

Best Answer

The format of an FTP list output was not standardised for computer parsing, so if you want to support all possible FTP servers, you need to come up with your own parser.

But let's start with the easiest way: PHP supports an FTP wrapper. Since PHP 5.1 you can use filemtime() to fetch the modification file of a remote file by using ftp://user:password@host/path/file as argument.

You can also try to use curl_getinfo() of the PHP cURL extension.

If that does not work because your FTP server is of AIX, VMS, EBCDIC or some other "exotic" nature, you can parse the directory listing manually.

First of all, if you are very lucky, the FTP server supports MLST or MLSD command. You can issue them using ftp_raw() in PHP. The output is explained in RFC 3659. The date can easily be parsed and is returned in UTC.

If you are less lucky, you need to fall back to the legacy LIST command used by ftp_rawlist(). There is no standard on how the output looks like, so you need heuristics. FileZilla is very good at handling legacy FTP servers. If you really need a parser and have some time, simply port FileZilla's directory listing parser to PHP.