tags:

views:

687

answers:

2

In Java, I'm trying to log into an FTP server and find all the files newer than x for retrieval.

Currently I have an input stream that's reading in the directory contents and printing them out, line by line, which is all well and good, but the output is fairly vague... it looks like this...

-rw-------     1 vuser  4773 Jun 10  2008 .bash_history
-rw-r--r--     1 vuser  1012 Dec  9  2007 .bashrc
lrwxrwxrwx     1 root      7 Dec  9  2007 .profile -> .bashrc
drwx------     2 vuser  4096 Jan 30 01:08 .spamassassin
drwxr-xr-x     2 vuser  4096 Dec  9  2007 backup.upgrade_3_7
dr-xr-xr-x     2 root   4096 Dec 10  2007 bin

etc...

however, I need the actual timestamp in seconds or milliseconds so that I can determine if I want that file or not.

I assume this has something to do with the FTP server's configuration? but I'm kind of stumped.

+4  A: 

Maybe worth having a look at the Jakarta Commons Net API which has FTP functionality.

I think with it you can use list files which will give you file objects that you can do getTimeStamp's on, you then should be able to get just the ones you need.

Mark Davidson
that works, thanks!
Dr.Dredel
+2  A: 

Unfortunately, the output of an FTP servers directory listing is not mandated by the standard. In fact, it is explicitly described as not intended for machine parsing. The format will vary quite a bit between servers on some operating systems.

RFC 3659 describes some extensions to the FTP standard including the "MDTM" command for querying modification times. If you are lucky, the servers that you want to talk to have implemented this extension.

Darron
+1 this helped me, though the server I was talking to implemented it as MODTIME <filename>
Paul Dixon
I was doing this in PHP, and have now found it already had a ftp_mdtm() function :)
Paul Dixon