Skip to content

Instantly share code, notes, and snippets.

@heiko-braun
Created December 4, 2023 10:45
Show Gist options
  • Save heiko-braun/d73ebf5b24767f7b5d7b1da8613b6de4 to your computer and use it in GitHub Desktop.
Save heiko-braun/d73ebf5b24767f7b5d7b1da8613b6de4 to your computer and use it in GitHub Desktop.

Keywords: Apache Camel | FTP | copy file

Messages

user: I am copying file from ftp to local system and file is in gigs. I notice that each time when I tried to copy file in iteration it overrides the content. Tried using .done extension but didn't worked also tried to copy file to another folder but that's also overlapping. How can I make this work?

assistant: It seems that you are looking to copy files from an FTP server to your local system without overwriting the existing files. One approach to achieve this is to dynamically set the filename using the File Language options available in the Apache Camel FTP component.

You can use the fileName option with a dynamic expression to set the filename and avoid overwriting existing files. Additionally, you can use the doneFileName option to create a separate flag file (done file) when the original file has been written, which prevents overwriting.

Here is an example of how you can achieve this in a Camel route using Java DSL and Maven dependencies:

from("sftp://username@hostname:port//remoteDir?password=password&delete=true&fileName=myfile.txt&doneFileName=myfile.done")
.to("file://targetDir?fileName=${file:onlyname.noext}.txt");

Maven artifact references for the necessary dependencies:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>x.x.x</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-ftp</artifactId>
    <version>x.x.x</version>
</dependency>

In the example above:

  • We are using the fileName option to specify the filename filter for the consumer.
  • The doneFileName option is used to create a separate flag file when the original file has been written.

You can customize the filename and doneFileName expressions to suit your specific requirements.

Please ensure you replace x.x.x with the appropriate version of Apache Camel for your project.

Let me know if you need further assistance or if you have additional questions!

@orpiske
Copy link

orpiske commented Dec 4, 2023

Needs review:

  • Maybe needs a doneFileName on the producer side instead of the consumer side.
  • Maybe needs a idempotent consumer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment