Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-244

Add a FTPClient.listFiles(FTPFileFilter) method

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.2
    • FTP
    • None

    Description

      It would be nice if there was a way to list only those files I'm interested in. I've had to write a loop a couple of times to figure out which files had the right naming conventions. If the API handled that for me, I would have less boilerplate code to write.

      I would attach a patch but as of this time I cannot download the source due to an internal server error.

      I was imagining the introduction of a new interface org.apache.commons.net.ftp.FTPFileFilter that would be analogous to java.io.FileFilter:

      package org.apache.commons.net.ftp;
      
      public interface FTPFileFilter {
         public boolean accept(FTPFile file);
      }
      

      A new method on FTPClient would need to be created to support it. Here's a code sample using API calls:

      public FTPFile[] listFiles(FTPFileFilter filter) throws IOException {
         FTPFile files = listFiles();
         List<FTPFile> fileList = new ArrayList<FTPFile>(files.length);
         for (FTPFile file : files) {
            if (filter.accept(file)) {
               fileList.add(file);
            }
         }
         return fileList.toArray(new FTPFile[fileList.size()]);
      }
      

      See java.io.File.listFiles(java.io.FileFilter) for comparison.

      Attachments

        1. NET-244.pat
          230 kB
          Hasan Diwan

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mjlachman Matt Lachman
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: