Ftp – Getting modified year of file via FTP

ftppython

I want to compare the modified date of a local file and the equivalent file on a remote FTP site (via FTP, no SSH access). I'm using Python's ftplib btw. The only way I can find to get the remote modified date is by using the dir command, but that doesn't output the year. Using gFTP shows the year in the modified date, so there must be a way of getting that information. Any ideas?

Best Answer

If your FTP server supports it, you could try using the MDTM command. This returns the file modification time in the format YYYYMMDDHHMMSS.sss. The milliseconds are optional and the time is in GMT.

It doesn't look like ftplib supports MDTM directly, but you should be able to call it with sendcmd:

ftp.sendcmd('MDTM filename')