title: Apache vfs: fetch latest changed file of a directory (sftp)
body: <p>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:</p>
  
  <pre><code>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() &gt; max) {
              max = fob.getContent().getLastModifiedTime();
              latestFile = fob;
          }
      }
      return latestFile;
  }
  </code></pre>
  
  <p>The problem with this approach is that I am basically downloading every file in the given directory, everytime the method is called. </p>
  
  <p>Is there any better way to do this?</p>