user2508615
user2508615

Reputation: 220

How to rename and move the file on FTP once processed by camel?

I have several folders on my ftp:

/csv
/xml
/processed
/....

How can I rename and move each file once it has been processed from file.csv to file.done and move it to processed folder ? I have tried many options like adding tons of parameters to "from" or add something into onCompletion or adding several more routes for just moving files. All placeholders contain correct values and are processed by Spring.

<route>
            <from uri="ftp://{{ftp.user}}@{{ftp.server}}/{{inbound.csv}}?password={{ftp.pass}}&amp;binary=true&amp;include=.*csv"/>
            <onCompletion onCompleteOnly="true">
                <to uri="ftp://{{ftp.user}}@{{ftp.server}}/{{outbound.csv}}?password={{ftp.pass}}&amp;doneFileName=${file:name}.done"/>
            </onCompletion>
            <delay>
                <constant>15000</constant>
            </delay>
            <unmarshal><csv/></unmarshal>
            <to uri="bean:cSVHandler?method=process"/>
        </route>

Please help.

Upvotes: 1

Views: 9329

Answers (2)

Ludi
Ludi

Reputation: 463

In case someone finds this post and does only want to rename the file, you can add

&move=${headers.CamelFileName}.old

Upvotes: 4

Claus Ibsen
Claus Ibsen

Reputation: 55540

Use the move option which will move/rename the file after its processed,

<from uri="ftp://{{ftp.user}}@{{ftp.server}}/{{inbound.csv}}
      ?password={{ftp.pass}}&amp;binary=true&amp;include=.*csv
      &amp;move=../processed"/>

Which will move the file into the ../processed directory.

See more details about the move option at http://camel.apache.org/file2

Upvotes: 4

Related Questions