简体   繁体   English

从FTP文件列表中获取项目的时间戳

[英]Obtain timestamp of items from FTP file list

In Java, I'm trying to log into an FTP server and find all the files newer than x for retrieval. 在Java中,我正在尝试登录到FTP服务器并找到比x更新的所有文件以进行检索。

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? 我认为这与FTP服务器的配置有关? but I'm kind of stumped. 但我有点难过。

Maybe worth having a look at the Jakarta Commons Net API which has FTP functionality. 也许值得一看有FTP功能的Jakarta Commons Net API。

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. 我认为你可以使用列表文件来为你提供getTimeStamp的文件对象,然后你应该能够得到你需要的文件对象。

Unfortunately, the output of an FTP servers directory listing is not mandated by the standard. 不幸的是,标准没有规定FTP服务器目录列表的输出。 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. RFC 3659描述​​了FTP标准的一些扩展,包括用于查询修改时间的“MDTM”命令。 If you are lucky, the servers that you want to talk to have implemented this extension. 如果幸运的话,您要与之通话的服务器已实现此扩展。

getTimestamp() gets you the last modification time of the file. getTimestamp()获取文件的最后修改时间。 If you're trying to get the time when the file was uploaded to the server, that wouldn't work. 如果您正在尝试获取文件上传到服务器的时间,那将无法正常工作。 I'm trying to do something similar, I want to get all files that were uploaded after X time. 我正在尝试做类似的事情,我想获得在X时间之后上传的所有文件。 I couldn't find of a clean way of doing this without actually doing a ls and parsing through that. 如果没有实际执行ls并解析它,我找不到干净的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM