aspose file tools*
The moose likes Other Open Source Projects and the fly likes To get the last modified timestamp of a remote file over an ftp connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "To get the last modified timestamp of a remote file over an ftp connection" Watch "To get the last modified timestamp of a remote file over an ftp connection" New topic
Author

To get the last modified timestamp of a remote file over an ftp connection

ruth abraham
Greenhorn

Joined: Oct 31, 2012
Posts: 9
Hi,
At present, my application (running on, say Server 1) uses ftp connections (raw ftp commands) to connect to certain servers (say Server2 .... server n) within the network, access a particular path on server 2...n, list all the files in that directory, get the last modified time stamp of each file using MDTM and using some logic, filters out the required files based on this MDTM value.
Recently we came upon a server 2 whose ftp version does not support the MDTM command and they are pretty adamant about not supporting this command.
So now we will have to change our logic to get the file time stamps without using MDTM.

Any idea what my options are?



ruth abraham
Greenhorn

Joined: Oct 31, 2012
Posts: 9
oops...forgot to mention, I cant use org.apache.commons.net.ftp.FTPClient.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2615
    
    9

Welcome to the Ranch Ruth. Have you checked the commons FTP API? FTPClient class


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

My next step would be to ask the owner of the site what command their server supports which returns the last-modified timestamp of a file. If there isn't one, then no FTP client software is going to be able to get that timestamp.

And in that case the problem would be out of your hands and onto the desk of somebody else. It would then be a political problem and not a programming problem.
ruth abraham
Greenhorn

Joined: Oct 31, 2012
Posts: 9
Thanks K! Great to be here! and thank you for your reply...

Paul, I guess you are right...But I am confused about one thing...If we were to connect to the same Server 2 using sftp, it works and we are able to get the time stamp. But for sftp connections we use the Maverick SFTP API and not our application code and are able to get a list of file object using a very simple "_sftpClientSession.ls(dirName)" !. So I tried checking the Maverick code to see what they would've used for this. However, I got overwhelmed, lost track and couldnt get to that point
I believe they would be using some ftp raw command ultimately......any leads in this direction???
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Well, that's interesting. Since I know really nothing about SFTP, I did a little bit of research. First of all Wikipedia says "sftp should not be confused with running an FTP client over an SSH connection" -- in other words, SFTP is not just a kind of FTP, it's a completely different thing.

The page I was looking at, this one: SSH File Transfer Protocol, gave me some links to the actual SFTP specs, but I didn't look at them. For one thing it's time for me to turn off the computer now, but mainly I already got the idea that SFTP isn't FTP.

But now that you've found out that SFTP works and can give you the information you want, can't you just use that instead of FTP?
ruth abraham
Greenhorn

Joined: Oct 31, 2012
Posts: 9
Thanks Paul....That does make sense....Apparently the server 2 team have no such command that returns the timestamp...So I guess I'll rework our logic...
I wish we could stick with sftp. Unfortunately though, they require both ftp and sftp support. Will come up with a workaround that would not need the timestamp.
Thank you for all your help....Appreciate it!
 
 
subject: To get the last modified timestamp of a remote file over an ftp connection