如何在Java中使用正则表达式通过FTP客户端复制文件
我正在使用上述FTPClient将文件从Linux机器下载到Windows机器。对于预期的文件,它工作正常 但我正试图用正则表达式实现同样的效果。例如,/home/test/workspace/*.xml,将下载到C:/Users/workspace/* 使用或列出远程目录中的文件 迭代列表以查找与您的模式匹配的文件 逐个下载匹配的文件如何在Java中使用正则表达式通过FTP客户端复制文件,java,regex,ftp,ftp-client,apache-commons-net,Java,Regex,Ftp,Ftp Client,Apache Commons Net,我正在使用上述FTPClient将文件从Linux机器下载到Windows机器。对于预期的文件,它工作正常 但我正试图用正则表达式实现同样的效果。例如,/home/test/workspace/*.xml,将下载到C:/Users/workspace/* 使用或列出远程目录中的文件 迭代列表以查找与您的模式匹配的文件 逐个下载匹配的文件 String server = "www.test.com"; int port = 21; String username = "test"; String
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();
}
}