Nagesh
Nagesh

Reputation: 347

Apache Camel File2 include only specific subfolders from the source directory

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.");
}

Upvotes: 0

Views: 3008

Answers (2)

Claus Ibsen
Claus Ibsen

Reputation: 55550

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).

Upvotes: 1

ShellDragon
ShellDragon

Reputation: 1722

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.

Upvotes: 0

Related Questions