public class FTPMultipleFileLookup implements FTPFileFilter {
FTPClient ftpClient = new FTPClient();
FTPFile[] result;
List<String> filePatterns;
String pathname;
FTPFileFilter filter;
public FTPMultipleFileLookup(List<String> filePatterns) {
this.filePatterns = filePatterns;
}
@Override
public boolean accept(FTPFile ftpFile) {
return (ftpFile.isFile() && filePatterns.contains(ftpFile.getName()));
}
}
public class MultipleFilelookup {
public static void main(String[] args) {
String server = "XXXXX";
int port = XX;
String user = "XXX";
String pass = "XXXXXX";
//final String file = "lookup.txt";
//List<String> filePatterns = new ArrayList<String>();
List<String> filePatterns = Arrays.asList("lookup.txt","loookup.txt");
FTPClient ftpClient = new FTPClient();
try{
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
String dirToSearch = "XXXXXXX";
FTPMultipleFileLookup filter = new FTPMultipleFileLookup(filePatterns) {
@Override
public boolean accept(FTPFile ftpFile) {
boolean accept = false;
String fileName = ftpFile.getName();
for(String pattern : filePatterns){
if(fileName.contains(pattern)){
accept = true;
break;
}
}
return accept;
}
};
FTPFile[] result = ftpClient.listFiles(dirToSearch, filter);
if (result != null && result.length > 0) {
System.out.println("SEARCH RESULT:");
//InputStreamReader reader = new InputStreamReader(result);
for (FTPFile aFile : result) {
System.out.println(aFile.getName());
}
}
ftpClient.logout();
ftpClient.disconnect();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (ftpClient.isConnected()) {
try {
ftpClient.disconnect();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE