0
votes

I am using Apache Camel File2 (SFTP) (with Camel Latest version) and Java8 API. I am trying to develop a MyRouteBuilder.java class which extends RouteBuilder class and implements the configure method.

I want to transfer files from source path to destination path. Here in the source endpoint, specifying the URI parameter "include" to include files from particular specific subfolders under the source path like "SubFolder1, SubFolder2, SubFolder3".

Example Source URIs: 1) "file:\src\SubFolder1\.*\.txt" 2) "file:\src\SubFolder2\.*\.txt"

I have tried with the multiple examples below and even Examples:

 1) include=.SubFolder[1-2]\.*\.txt
 2) include=.SubFolder1|SubFolder2\.*\.txt
 3) include=SubFolder[1-2]\.*\.txt
 4) include=SubFolder1\.*\.txt
 5) include=.SubFolder(?)\.*\.txt

Nothing is working.

Please suggest a way to solve using Apache Camel File2 API using Java.

public void configure() throws Exception {

    String sftpUrl = "sftp://" + user + "@" + hostName + sourcePath + "?" + "noop=true"
            + "&recursive=true&include=.*\\.txt$"+"&strictHostKeyChecking=no" + "&useUserKnownHostsFile=true" + "&password=RAW("
            + password + ")&preferredAuthentications=publickey,keyboard-interactive,password";  

    System.out.println("\n\n sftpUrl + " + sftpUrl + "\n\n");

    from(sftpUrl)
        .log(" Copying File : ${file:name} ").process(exchange -> {
        System.out.println("1. Processing a File  --> = " + exchange);
    }).to("file://" + destPath)
            // ;
    .log("Uploading file ${file:parent} / ${file:name} complete.");
}
2
Presuming you have tried examples from the official docs. Can you show us your route builder code (whatever you have). "Nothing is working" is not a good problem statement. Tell is what exactly is not working - ShellDragon
include parameter regex is not working - Nagesh
String sftpUrl = "sftp://" + user + "@" + hostName + sourcePath + "?" + "noop=true" + "&recursive=true&include=.SubFolder1\\\*\\.txt$"+"&strictHostKeyChecking=no" + "&useUserKnownHostsFile=true" + "&password=RAW(" + password + ")&preferredAuthentications=publickey,keyboard-interactive,password"; - Nagesh
That looks like the ftp2 component and not File2. FTP2 doesn't support include. Please post your whole route in the question not here in comments. - ShellDragon

2 Answers

0
votes

As @hk6279 indicated below, FTP2 inherits File2 and File2 behaviors are available on FTP2 unless stated otherwise. However, a very important part that OP might have missed out was highlighted by @hk6279.

Only files (not directories) are matched for valid filename, if options such as: include or exclude are used.

May be this is what is causing trouble.


Looks like you are referring to FTP2 component and not file2 component. Please have a look at the FTP component's test cases to see how filtering is implemented. It does not support include option as you can see in the docs.

1
votes

You should use antInclude as it supports both directories and files. And btw the Camel website is undergoing a complete redesign, and in the mean-time the up-to-date component documentation can be browsed from github.

antInclude=F1/*.txt,F2/*.txt

So look at: https://github.com/apache/camel/blob/master/components/camel-ftp/src/main/docs/ftp-component.adoc

And also mind you can browser per version documentation (choose branch/tag).