M-Zee
M-Zee

Reputation: 47

Apache Camel File Formats

I am working on a project that automatically uploads files to the SFTP server. My project is now in production and functioning as per the initial requirement spec. My project picks-up a txt file from a predefined location. Now because of the size limit on the SFTP server, the txt file must now be Zipped before the upload.

I now want to change my camel route to cater not only for txt files but also for xls, csv and Zip files.

How do i do that?

Currently my route looks as follows:

from("quartz://myscheduler?cron={{cron}}")
.pollEnrich("file:{{pickuplocation}}?moveFailed=error/${file:name.noext}_${date:now:yyyyMMddHHmmssSSS}.${file:ext}&move=SFTPCompleted/${date:now:MMM}-${date:now:yyyy}/${file:name.noext}_${date:now:yyyyMMddHHmmssSSS}.${file:ext}") 
        .setHeader("CamelFileName", simple("${file:name}"))
        .setHeader("RouteID",constant("Route ID"))          
        .multicast()
            .to("sftp://"+username+"@"+SftpLocation+"password="+password+"&stepwise=false&disconnect=true&fileName=${file:name.noext}.txt")
        .end()

TIA

Upvotes: 1

Views: 1015

Answers (1)

Geert Schuring
Geert Schuring

Reputation: 2163

I don't see why you use such a complicated way of copying files. If I'm not mistaken you could just use this:

from("file:{{pickuplocation}}?moveFailed=error/${file:name.noext}_${date:now:yyyyMMddHHmmssSSS}.${file:ext}&move=SFTPCompleted/${date:now:MMM}-${date:now:yyyy}/${file:name.noext}_${date:now:yyyyMMddHHmmssSSS}.${file:ext})
.to("sftp://"+username+"@"+SftpLocation+"password="+password+"&stepwise=false&disconnect=true")

This will pickup any file in the pickupLocation directory and the FTP compenent will write the file with the same name to the remote server.

You can use the 'include' parameter of the File component to set a regex to match only certain file types: http://camel.apache.org/file2.html

Upvotes: 2

Related Questions