piyushGoyal
piyushGoyal

Reputation: 1099

Apache Camel | FTP | Consuming only single file

I am trying to read all the text files in a ftp directory, parse them. If the parsing is successful, then move them to a different directory(not the default one i.e. .done directory) and if the parsing fails then file should remain in the ftp directory. The concept looks simple but then my route only reads a single file from ftp and routes ends itself after fetching one file.

Following is the code:

@Override
    public void configure() throws Exception {

         from(EndPointConstants.DIRECT + GetDriverProductInfo.class.getSimpleName())  
        .pollEnrich(ftp://[email protected]/fantics?password=******&recursive=true)
        .to("file://test/readFile")

Is it something related to pollEnrich that its only able to get a single file and the process is not happening recursively?

Upvotes: 2

Views: 8068

Answers (1)

Evan P
Evan P

Reputation: 1817

If the parsing is successful, then move them to a different directory(not the default one i.e. .done directory)

Use something like this example:

.to("file://test/readFile?autoCreate=true&moveFailed=.failed/${date:now:yyyyMMdd}/${file:name}&move=.processed/${date:now:dd-MM-yyyy}/${file:name}")

From the Camel Documentation (FTP/SFTP/FTPS Component):

The FTP consumer will by default leave the consumed files untouched on the remote FTP server. You have to configure it explicitly if you want it to delete the files or move them to another location. For example you can use delete=true to delete the files, or use move=.done to move the files into a hidden done sub directory. The regular File consumer is different as it will by default move files to a .camel sub directory. The reason Camel does not do this by default for the FTP consumer is that it may lack permissions by default to be able to move or delete files.

So You can use for example:

&noop=false

&move

&delete=false

EDIT:

I think you should come up with something like this (the following code) as pollEnrich() doesn't suite for this case.

(The following code is highly discouraged to be used as it is rather than an example of use)

from("direct:scan")
    .process(new Processor()
    {
        public void process(Exchange exchange) throws Exception
        {
            ConsumerTemplate consumerTemplate = exchange.getContext().createConsumerTemplate();
            ProducerTemplate producerTemplate = exchange.getContext().createProducerTemplate();
            producerTemplate.setDefaultEndpointUri("file:..");
            producerTemplate.send(consumerTemplate.receive("ftp:.."));
        }
    });

Cheers!

Upvotes: 3

Related Questions