Hello,
I am trying to pull the latest file out of a directory, which is located on a sftp server. The way I do it right now is more or less:
public FileObject getLatestFile(String directory) throws FileSystemException {
FileObject fo = fsManager.resolveFile(this.host+directory, fsOptions);
FileObject latestFile = null;
long max = 0;
fo.getContent().
for (FileObject fob : fo.getChildren()){
if (fob.getContent().getLastModifiedTime() > max) {
max = fob.getContent().getLastModifiedTime();
latestFile = fob;
}
}
return latestFile;
}
The problem with this approach is that I am basically downloading every file in the given directory, everytime the method is called.
Is there any better way to do this?