Chinmoy
Chinmoy

Reputation: 503

How to copy a file with FTP Client using regular expression in Java

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

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202534

Upvotes: 0

Related Questions