Solvemon
Solvemon

Reputation: 1461

Apache Camel: rename (S)FTP target file to prevent overwriting

I am attempting to set up a route from one SFTP location to another, moving the files (not copying). I would like to prevent target files from being overwritten if a source file has the same name.

My route currently looks like this:

from("sftp://camel@server1/Source?password=camel&delete=true").to("sftp://camel@server2/Target?password=camel");

My problem is that a new file in Source with the same name as an earlier one will overwrite the target file in server2. How can I tell Camel to give the target a new name if it already exists?

Thanks!

Upvotes: 1

Views: 2612

Answers (1)

Sumit Singh
Sumit Singh

Reputation: 15906

From File Component For FileExist

What to do if a file already exists with the same name. The following values can be specified: Override, Append, Fail, Ignore, and Move. Override, which is the default, replaces the existing file. Append adds content to the existing file. Fail throws a GenericFileOperationException, indicating that there is already an existing file. Ignore silently ignores the problem and does not override the existing file, but assumes everything is okay. The Move option requires Camel 2.10.1 onwards, and the corresponding moveExisting option to be configured as well. The option eagerDeleteTargetFile can be used to control what to do if an moving the file, and there exists already an existing file, otherwise causing the move operation to fail. The Move option will move any existing files, before writing the target file.

So you can throw exception and catch it and move it with different name.

Upvotes: 1

Related Questions