Reputation: 503
String server = "www.test.com";
int port = 21;
String username = "test";
String password = "test";
FTPClient ftpclient = new FTPClient();
try {
ftpclient.connect(server,port);
ftpclient.login(username, password);
ftpclient.enterLocalPassiveMode();
ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
String remoteFile = "/home/test/workspace/9001_20150918165942_00085.xml";
File downloadfile = new File("C:/Users/Workspace/9001_20150918165942_00085.xml");
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadfile));
boolean success = ftpclient.retrieveFile(remoteFile, outputStream1);
outputStream1.close();
if (success) {
System.out.println("File has been downloaded successfully.");
}
} catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
if (ftpclient.isConnected()) {
ftpclient.logout();
ftpclient.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
I am using the above FTPClient
to download a file from a Linux machine to Windows machine. For the intended file it's working fine.
But I am trying to achieve the same using regular expression. For instance, /home/test/workspace/*.xml
which will be downloaded to C:/Users/Workspace/*
.
Upvotes: 0
Views: 1356
Reputation: 202534
Use the FTPClient.mlistDir
method (or FTPClient.listFiles
) to list files in the remote directory
Iterate the list to find files matching your pattern.
Download the matched files, one by one.
Upvotes: 0