I am trying to fetch last modified date of a file from FTP environment.The result is not as expected.
By using ftpClient.getModificationTime("File path")
I am getting null.
By using FTPFile.getTimestamp().getTime()
I am getting wrong last modified (i.e. real last modified is of today and I am getting Wed Feb 18 02:55:22 EST 2004).
How to get correct last modified?File at FTP
Thanks in advance.
I found the mistake I was doing.
I was working on a SFTP Environment instead of FTP Environment. I had to use jar files and other functions of SFTP not of FTP.
Thanks.
FTPClient.getModificationTime
returnsnull
when the server returns an error response toMDTM
command. Typically that would mean either that:MDTM
command.Check
FTPClient.getReplyString()
.If it turns out that the FTP server does not support
MDTM
command, you will have to use another method to retrieve the timestamps. IfMDTM
is not supported,MLSD
won't be either.In that case the only other way is using
LIST
command to retrieve listing of all files and lookup the file you need - UseFTPClient.listFiles()
.See also Make FTP server return files listed by timestamp with Apache FTPClient.