如何在 Java 中使用正则表达式通过 FTP 客户端复制文件

问题描述 投票:0回答:1
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();
    }
}

我正在使用上面的

FTPClient
将文件从Linux机器下载到Windows机器。对于预期的文件,它工作正常。

但我正在尝试使用正则表达式来实现相同的目的。例如,

/home/test/workspace/*.xml
将下载到
C:/Users/Workspace/*

java regex ftp ftp-client apache-commons-net
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.