1

I need to find the latest created file in a FTP folder. However the FTP server is not returning full timestamps for files with the LIST command (missing the year):

drwxr-xr-x   2 owner    group               0 Nov  9 17:29 archive
drwxr-xr-x   2 owner    group               0 Nov  9 17:35 category
drwxr-xr-x   2 owner    group               0 Jan  9 07:21 images

And the MLSD command is not supported.

So currently I check the timestamp of each file with the MDTM command. Is there a more efficient way?

I am using the ftplib wrapper.

2
  • It's far from obvious but your mention of ftplib and the inclusion of the python tag gives me he impression that you're looking for a programming solution. If so, this should have been asked on Stack Overflow. Jan 30, 2013 at 9:09
  • I am after the FTP command to get the timestamps reliably and efficiently. Should that go on SO?
    – hoju
    Jan 31, 2013 at 12:07

2 Answers 2

1

man ftp says:

 ls [remote-directory] [local-file]
             Print a listing of the contents of a directory on the remote machine.
             The listing includes any system-dependent information that the server
             chooses to include; for example, most UNIX systems will produce output
             from the command ‘ls -l’.  (See also nlist.)  If remote-directory is
             left unspecified, the current working directory is used.  If interac‐
             tive prompting is on, ftp will prompt the user to verify that the last
             argument is indeed the target local file for receiving ls output.  If
             no local file is specified, or if local-file is ‘-’, the output is
             sent to the terminal.

So, most UNIX systems will produce output from the command ‘ls -l’ and such command either shows date or date and time, depending on the “age” of file:

-rw-rw-r-- 1 user group        4 ene 21 12:40 keepalive.out
-rw-rw-r-- 1 user group   525292 oct  4  2013 Linux.svg

Taking into account you are after the FTP command to get the timestamps reliably and efficiently, I'm affraid your approach (MDTM command) is the only one not including programming stuff.

0

You might want to try ftputil. Although it is not a standard python module, not part of the batteries included, it has similar features as os.stat. That allows you to get detail file stats such as file creation date, size etc. It is a high-level interface to the ftplib.

You might also find this link useful -

http://mcdc.missouri.edu/libs/python/ftputil/ftputil.html

1
  • It says for 'lstat' function: Values for the time of the last modification may be rough, depending on the information from the server. For timestamps older than a year, this usually means that the precision of the modification timestamp value is not better than days. For newer files, the information may be accurate to a minute.
    – djangofan
    Jan 30, 2013 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .