【问题标题】:How to copy a file with FTP Client using regular expression in Java如何使用 Java 中的正则表达式使用 FTP 客户端复制文件
【发布时间】:2015-09-22 05:25:48
【问题描述】:
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】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-24
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-13
      • 2017-08-22
      相关资源
      最近更新 更多