You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by mcheng <hm...@gmail.com> on 2012/02/19 08:28:27 UTC

rename file with camel ftp

There is a file in ftp server and  I have made some  attempts to rename it,
but it's always failed.
Below is my code, can anyone give me some suggestions? I will be very
appreciated.


public void process(Exchange exchange) throws Exception {
				GenericFile genericFile = (GenericFile) exchange.getIn().getBody();
				genericFile.changeFileName("newName");
				exchange.getIn().setBody(genericFile);
}
				

 

--
View this message in context: http://camel.465427.n5.nabble.com/rename-file-with-camel-ftp-tp5496480p5496480.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: rename file with camel ftp

Posted by Claus Ibsen <cl...@gmail.com>.
And next time use the @user mailing list to get help about Camel.

The @dev is for discussing development on the actual project itself,
not for end users to ask how to do X, Y etc.


On Thu, Feb 23, 2012 at 9:48 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Thu, Feb 23, 2012 at 9:42 AM, mcheng <hm...@gmail.com> wrote:
>> Thanks for you replay. I have tried to use move argument, but it was just
>> moving to other folder. I want to change the file name in the same remote
>> directory.  Do you have other solution for this question?
>>
>
> By default the move option assumes its another directory. If you want
> to rename the file in the same directory, you need to configure the
> move option with the file name tokens, such as
>
> move=${file:name}.error
>
> Which will rename the file to have .error appended. See the tokens at:
> http://camel.apache.org/file-language.html
>
> See more at section _Fine grained control over Move and PreMove option_ at
> http://camel.apache.org/file2
>
> Mind you may have to use a filter to exclude the failed files to avoid
> picking them up again.
>
>
>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/rename-file-with-camel-ftp-tp5496480p5507363.html
>> Sent from the Camel Development mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: rename file with camel ftp

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Feb 23, 2012 at 9:42 AM, mcheng <hm...@gmail.com> wrote:
> Thanks for you replay. I have tried to use move argument, but it was just
> moving to other folder. I want to change the file name in the same remote
> directory.  Do you have other solution for this question?
>

By default the move option assumes its another directory. If you want
to rename the file in the same directory, you need to configure the
move option with the file name tokens, such as

move=${file:name}.error

Which will rename the file to have .error appended. See the tokens at:
http://camel.apache.org/file-language.html

See more at section _Fine grained control over Move and PreMove option_ at
http://camel.apache.org/file2

Mind you may have to use a filter to exclude the failed files to avoid
picking them up again.



>
> --
> View this message in context: http://camel.465427.n5.nabble.com/rename-file-with-camel-ftp-tp5496480p5507363.html
> Sent from the Camel Development mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: rename file with camel ftp

Posted by mcheng <hm...@gmail.com>.
Thanks for you replay. I have tried to use move argument, but it was just
moving to other folder. I want to change the file name in the same remote
directory.  Do you have other solution for this question?


--
View this message in context: http://camel.465427.n5.nabble.com/rename-file-with-camel-ftp-tp5496480p5507363.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: rename file with camel ftp

Posted by Reuben Garrett <re...@gmail.com>.
mcheng,

I don't have an immediate explanation, but I may have a solution.  Did you
observe any Exceptions being thrown?  If so, they could help trace the root
cause.  I suspect, however, that the GenericFile you're obtaining from the
Exchange is just a descriptor of sorts, and that changes to its name do not
automagically rename the underlying file - however I don't know for sure.

Beyond that, you may have better luck using the built-in moving behavior of
the FTP component by specifying a rename target in the endpoint URI's "move"
argument.  By default, bare tokens are interpreted as directories - however
you should be able to use an
Expression<http://camel.apache.org/expression.html>to fine-tune a
rename strategy as described in the File component's user
guide:
http://camel.apache.org/file2.html#File2-FinegrainedcontroloverMoveandPreMoveoption

Hope this helps!
Reuben Garrett

On Sun, Feb 19, 2012 at 01:28, mcheng <hm...@gmail.com> wrote:

> There is a file in ftp server and  I have made some  attempts to rename it,
> but it's always failed.
> Below is my code, can anyone give me some suggestions? I will be very
> appreciated.
>
>
> public void process(Exchange exchange) throws Exception {
>                                GenericFile genericFile = (GenericFile)
> exchange.getIn().getBody();
>                                genericFile.changeFileName("newName");
>                                exchange.getIn().setBody(genericFile);
> }
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/rename-file-with-camel-ftp-tp5496480p5496480.html
> Sent from the Camel Development mailing list archive at Nabble.com.
>