private static void getFTPFileProperties(FTPClient client,
String ftpLocation, String pattern) throws IOException {
FTPFile[] fileList=null;
fileList = client.listFiles();
for(int i=0;i<fileList.length;i++)
{
FTPFile file= fileList[0];
Calendar cal = file.getTimestamp();
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormater.format(cal.getTime()));
}
}
我编写了上述函数来检索文件详细信息。但不知何故,我正在检索没有文件秒部分的详细信息。 我正在将
lastModifiedDate
检索为 2013-08-08 00:00:00
,其中实际的 lastModifiedDate
是 2013-08-08 12:53:27 PM
FTPClient.listFiles
使用古老的 LIST
命令。使用该命令,FTP 服务器返回类似于 Unix ls
命令的列表是很常见的。对于旧文件(一年以上),它仅显示天精度的时间戳。
FTPClient.mlistDir
,它使用现代的 MLSD
命令,始终以秒精度检索时间戳。
public FTPFile[] mlistDir() throws IOException
当然,除非您连接到古老的 FTP 服务器,否则它不支持
MLSD
命令。
请注意,自 Apache Commons Net 3.0 起支持
mlistDir
。