简体   繁体   English

Apache Camel:重命名(S)FTP目标文件以防止覆盖

[英]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). 我正在尝试建立从一个SFTP位置到另一个SFTP位置的路由,将文件移动(而不是复制)。 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. 我的问题是,Source中与早期版本同名的新文件将覆盖server2中的目标文件。 How can I tell Camel to give the target a new name if it already exists? 如果目标已经存在,我如何告诉骆驼给目标重新命名?

Thanks! 谢谢!

From File Component For FileExist 来自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 . 可以指定以下值: OverrideAppendFailIgnoreMove 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. 失败引发GenericFileOperationException ,表明已经存在一个文件。 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. Move选项需要Camel 2.10.1及更高版本,并且还需要配置相应的moveExisting选项。 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. 选项eagerDeleteTargetFile可用于控制如果移动文件并且已经存在现有文件,该怎么办,否则会导致移动操作失败。 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. 因此,您可以引发异常并捕获它并以其他名称移动它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM