How to rename and move the file on FTP once proces

2019-08-04 07:40发布

问题:

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.

回答1:

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