[ 
https://issues.apache.org/jira/browse/NET-244?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Lachman updated NET-244:
-----------------------------

    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|http://java.sun.com/javase/6/docs/api/java/io/FileFilter.html]:
{code}
package org.apache.commons.net.ftp;

public interface FTPFileFilter {
   public boolean accept(FTPFile file);
}
{code}

A new method on FTPClient would need to be created to support it.  Here's a 
code sample using API calls:
{code}
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()]);
}
{code}

See 
[java.io.File.listFiles(java.io.FileFilter)|http://java.sun.com/javase/6/docs/api/java/io/File.html#listFiles(java.io.FileFilter)]
 for comparison.

  was:
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|http://java.sun.com/javase/6/docs/api/java/io/FileFilter.html]:
{code}
package org.apache.commons.net.ftp;

public interface FTPFileFilter {
   public boolean accept(FTPFile file);
}
{code}

A new method on FTPClient would need to be created to support it.  Here's a 
code sample using API calls:
{code}
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()]);
}
{code}

See 
[java.io.File.listFiles(java.io.FileFilter)|http://java.sun.com/javase/6/docs/api/java/io/File.html#listFiles(java.io.FileFilter)]
 for comparison.


Changed {{listFIles()}} to {{listFiles()}} in code sample.

> Add a FTPClient.listFiles(FTPFileFilter) method
> -----------------------------------------------
>
>                 Key: NET-244
>                 URL: https://issues.apache.org/jira/browse/NET-244
>             Project: Commons Net
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Matt Lachman
>            Priority: Minor
>         Attachments: NET-244.pat
>
>
> 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|http://java.sun.com/javase/6/docs/api/java/io/FileFilter.html]:
> {code}
> package org.apache.commons.net.ftp;
> public interface FTPFileFilter {
>    public boolean accept(FTPFile file);
> }
> {code}
> A new method on FTPClient would need to be created to support it.  Here's a 
> code sample using API calls:
> {code}
> 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()]);
> }
> {code}
> See 
> [java.io.File.listFiles(java.io.FileFilter)|http://java.sun.com/javase/6/docs/api/java/io/File.html#listFiles(java.io.FileFilter)]
>  for comparison.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to