Camel Component: FTP - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

This component provides access to remote file systems over the FTP and SFTP protocols.

Maven users will need to add the following dependency to their pom.xml for this component:

   <!-- use the same version as your Camel core version -->


FTPS (also known as FTP Secure) is an extension to FTP that adds support for the Transport Layer Security (TLS) and the Secure Sockets Layer (SSL) cryptographic protocols.


This component uses two different libraries for the FTP work. FTP and FTPS uses Apache Commons Net while SFTP uses JCraft JSCH .

URI format and Options


Where directoryname represents the underlying directory, which can contain nested folders.

If no username is provided, then anonymous login is attempted using no password. If no port number is provided, Camel will provide default values according to the protocol (ftp = 21, sftp = 22, ftps = 2222).

You can append query options to the URI in the following format, ?option=value&option=value&..., where option can be:

Table 9. 


Default Value




Specifies the username to use to log into the remote file system.



Specifies the password to use to log into the remote file system.



Specifies the file transfer mode, BINARY or ASCII. Default is ASCII ( false ).



Whether or not to disconnect from remote FTP server right after use. Can be used for both consumer and producer. Disconnect will only disconnect the current connection to the FTP server. If you have a consumer which you want to stop, then you need to stop the consumer/route instead.



When consuming, a local work directory can be used to store the remote file content directly in local files, to avoid loading the content into memory. This is beneficial if you consume a very big remote file and thus can conserve memory. See below for more details.



FTP and FTPS only : Specifies whether to use passive mode connections. Default is active mode ( false ).



FTPS only: Sets the underlying security protocol. The following values are defined: TLS : Transport Layer Security SSL : Secure Sockets Layer



FTPS only : Whether or not to disable using default values for execPbsz and execProt when using secure data transfer. You can set this option to true if you want to be in absolute full control what the options execPbsz and execProt should be used.



Starting with Camel 2.11, whether the FTP consumer should download the file. If this option is set to false, then the message body will be null, but the consumer will still trigger a Camel Exchange that has details about the file such as file name, file size, etc. It's just that the file will not be downloaded.



Starting with Camel 2.11, whether the consumer should download the entire file up front, the default behavior, or if it should pass an InputStream read from the remote resource rather than an in-memory array as the in-body of the Camel Exchange. This option is ignored if download is false or if localWorkDirectory is provided. This option is useful for working with large remote files.



FTPS only : This will use option P by default, if secure data channel defaults hasn't been disabled. Possible values are: C : Clear S : Safe (SSL protocol only) E : Confidential (SSL protocol only) P : Private



FTPS only : This option specifies the buffer size of the secure data channel. If option useSecureDataChannel has been enabled and this option has not been explicit set, then value 0 is used.



FTPS only: Sets the security mode(implicit/explicit). Default is explicit ( false ).



SFTP only: Sets the known_hosts file, so that the SFTP endpoint can do host key verification.



SFTP only: Sets the known_hosts file (loaded from classpath by default), so that the SFTP endpoint can do host key verification.



SFTP only: Sets the Java KeyPair for SSH public key authentication, it supports DSA or RSA keys.



SFTP only: Set the private key file to that the SFTP endpoint can do private key verification.



SFTP only: Set the private key file (loaded from classpath by default) to that the SFTP endpoint can do private key verification.



SFTP only: Set the private key as byte[] to that the SFTP endpoint can do private key verification.



SFTP only: Deprecated: use privateKeyPassphrase instead. Set the private key file passphrase to that the SFTP endpoint can do private key verification.



SFTP only: Set the private key file passphrase to that the SFTP endpoint can do private key verification.



SFTP only: Set the preferred authentications which SFTP endpoint will used. Some example include:password,publickey. If not specified the default list from JSCH will be used.



A comma separated list of ciphers that will be used in order of preference. Possible cipher names are defined by JCraft JSCH. Some examples include: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc. If not specified the default list from JSCH will be used.



If true, camel-ftp will use the list file directly to check if the file exists. Since some FTP servers may not support listing the file directly, if the option is false, camel-ftp will use the old way to list the directory and check if the file exists. Note this option also influences readLock=changed to control whether it performs a fast check to update file information or not. This can be used to speed up the process if the FTP server has a lot of files.



SFTP only: Sets whether to use strict host key checking. Possible values are: no, yes and ask. Note: ask does not make sense to use as Camel cannot answer the question for you as it is meant for human intervention.



Specifies the maximum reconnect attempts Camel performs when it tries to connect to the remote FTP server. Use 0 to disable this behavior.



Delay in milliseconds Camel will wait before performing a reconnect attempt.



the connect timeout in milliseconds. This corresponds to using ftpClient.connectTimeout for the FTP/FTPS. For SFTP this option is also used when attempting to connect.



FTP and FTPS Only: the SocketOptions.SO_TIMEOUT value in milliseconds. Note SFTP will automatic use the connectTimeout as the soTimeout .



FTP and FTPS Only: the data timeout in milliseconds. This corresponds to using ftpClient.dataTimeout for the FTP/FTPS. For SFTP there is no data timeout.



Whether or not to throw an exception if a successful connection and login could not be established. This allows a custom pollStrategy to deal with the exception, for example to stop the consumer.



FTP and FTPS Only: To execute site commands after successful login. Multiple site commands can be separated using a new line character (\n). Use help site to see which site commands your FTP server supports.



Whether or not stepwise traversing directories should be used or not. Stepwise means that it will 'cd' one directory at a time. See more details below. You can disable this in case you can't use this approach.



Dictates what path separator char to use when uploading files. Auto = Use the path provided without altering it. UNIX = Use unix style path separators. Windows = Use Windows style path separators.



FTP and FTPS Only: Allows you to use a custom instance.



FTP and FTPS Only: Allows you to use a custom org.apache.commons. net.ftp.FTPClientConfig instance.



FTPS Only: Sets the trust store file, so that the FTPS client can look up for trusted certificates.



FTPS Only: Sets the trust store type.

ftpClient.trustStore. algorithm


FTPS Only: Sets the trust store algorithm.

ftpClient.trustStore. password


FTPS Only: Sets the trust store password.



FTPS Only: Sets the key store file, so that the FTPS client can look up for the private certificate.



FTPS Only: Sets the key store type.

ftpClient.keyStore. algorithm


FTPS Only: Sets the key store algorithm.

ftpClient.keyStore. password


FTPS Only: Sets the key store password.

ftpClient.keyStore. keyPassword


FTPS Only: Sets the private key password.



FTPS Only: Reference to a org.apache.camel.util.jsse.SSLContext

Parameters in the Registry.  This reference overrides any configured SSL related options on ftpClient as well as the securityProtocol (SSL, TLS, etc.) set on FtpsConfiguration.  See Using the JSSE Configuration Utility.



SFTP Only: Reference to a com.jcraft.jsch.Proxy in the Registry.  This proxy is used to consume/send messages from the target SFTP host.



FTP/FTPS Only: Whether the consumer should use FTP LIST command to retrieve directory listing to see which files exists. If this option is set to false, then stepwise=false must be configured, and also fileName must be configured to a fixed name, so the consumer knows the name of the file to retrieve. When doing this only that single file can be retrieved. See further below for more details.




Whether the consumer should ignore when a file was attempted to be retrieved but did not exist (for some reason), or failure due insufficient file permission error.

Note besides those listed below, all options from the File are inherited and hence available to the FTP component.


By default, the FTPS component trust store accepts all certificates. If you only want to trust selective certificates, you have to configure the trust store with the options or by configuring a custom ftpClient.

You can configure additional options on the ftpClient and ftpClientConfig from the URI directly by using the ftpClient. or ftpClientConfig. prefix.

For example to set the setDataTimeout on the FTPClient to 30 seconds you can do:


You can mix and match and have use both prefixes, for example to configure date format or timezones.

from("ftp://foo@myserver?password=secret&" +

You can have as many of these options as you like.

See the documentation of the Apache Commons FTP FTPClientConfig for possible options and more details, and also Apache Commons FTP FTPClient.

If you do not like having complex configurations inserted in the url you can use ftpClient or ftpClientConfig by letting Camel look in the Registry for it. For example:

<bean id="myConfig" class="">
   <property name="lenientFutureDates" value="true"/>
   <property name="serverLanguageCode" value="fr"/>

And then let Camel lookup this bean when you use the # notation in the url.


More URI options


See Camel Component: File as all the options there also apply to this component.

Stepwise changing directories

Camel FTP can operate in two modes in terms of traversing directories when consuming files (for example, downloading) or producing files (for example, uploading)

  • stepwise

  • not stepwise

You may want to pick either one depending on your situation and security issues (some Camel end users can only download files if they use stepwise, while others can only download if they do not). You can use the stepwise option to control the behavior. See the online Camel documentation for examples of both techniques.



The FTP consumer (with the same endpoint) does not support concurrency (the backing FTP client is not thread safe). You can use multiple FTP consumers to poll from different endpoints. It is only a single endpoint that does not support concurrent consumers.

The FTP producer does not have this issue, it supports concurrency.

In the future we will add consumer pooling to Camel to allow this consumer to support concurrency as well.


This component is an extension of the Camel Component: File component, and there are more samples and details on the Camel Component: File component page.

Default when consuming files

The FTP consumer will by default leave the consumed files untouched on the remote FTP server. You have to configure it explicitly if you want it to delete the files or move them to another location. For example, you can use delete=true to delete the files, or use move=.done to move the files into a hidden done subdirectory.

The regular File consumer is different as it will (by default) move files to a .camel sub directory. The reason Camel does not do this by default for the FTP consumer is that it may lack permissions by default to be able to move or delete files.


The option readLock can be used to force Camel not to consume files that is currently in the progress of being written. However, this option is turned off by default, as it requires that the user has write access. There are only a few options supported for FTP. There are other solutions to avoid consuming files that are currently being written over FTP; for instance, you can write the file to a temporary destination and move the file after it has been written.

When moving files using move or preMove option the files are restricted to the FTP_ROOT folder. That prevents you from moving files outside the FTP area. If you want to move files to another area, you can use soft links and move files into a soft linked folder.

Message Headers

The following message headers can be used to affect the behavior of the component




Specifies the output file name (relative to the endpoint directory) to be used for the output message when sending to the endpoint. If neither CamelFileName or an expression are specified, then a generated message ID is used as the filename instead.


The absolute filepath (path + name) for the output file that was written. This header is set by Camel and its purpose is providing end-users the name of the file that was written.


Current index out of total number of files being consumed in this batch.


Total number of files being consumed in this batch.


The remote hostname.


Path to the local work file, if local work directory is used.

In addition the FTP/FTPS consumer and producer will enrich the Camel Message with the following headers.




Camel 2.11.1: The FTP client reply code (the type is a integer)


Camel 2.11.1: The FTP client reply string

About timeouts

The two set of libraries (see top) has different API for setting timeout. You can use the connectTimeout option for both of them to set a timeout in milliseconds to establish a network connection. An individual soTimeout can also be set on the FTP/FTPS, which corresponds to using ftpClient.soTimeout. Notice SFTP will automatically use connectTimeout as its soTimeout. The timeout option only applies for FTP/FTSP as the data timeout, which corresponds to the ftpClient.dataTimeout value. All timeout values are in milliseconds.

Using Local Work Directory

Camel supports consuming from remote FTP servers and downloading the files directly into a local work directory. This avoids reading the entire remote file content into memory as it is streamed directly into the local file using FileOutputStream .

Camel will store to a local file with the same name as the remote file, though with .inprogress as extension while the file is being downloaded. Afterwards, the file is renamed to remove the .inprogress suffix. And finally, when the Exchange is complete the local file is deleted.

So if you want to download files from a remote FTP server and store it as files then you need to route to a file endpoint such as:



Renaming the work file facilitates optimization. The route above is ultra efficient as it avoids reading the entire file content into memory. It will download the remote file directly to a local file stream. The handle is then used as the Exchange body. The file producer leverages this fact and can work directly on the work file handle and perform a to the target filename. As Camel knows it is a local work file, it can optimize and use a rename instead of a file copy, as the work file is meant to be deleted anyway.


In the sample below we set up Camel to download all the reports from the FTP server once every hour (60 min) as BINARY content and store it as files on the local file system.

protected RouteBuilder createRouteBuilder() throws Exception {
   return new RouteBuilder() {
   public void configure() throws Exception {
      // we use a delay of 60 minutes 
      //(for example, once per hour we poll the FTP server)
      long delay = 60 * 60 * 1000L;

      // from the given FTP server we poll (= download) all the files
      // from the public/reports folder as BINARY types and store this as 
      // files in a local directory. Camel will use the filenames from 
      // the FTPServer. Notice that the FTPConsumer properties must be
      // prefixed with "consumer.". In the URL the delay parameter is  
      // from the FileConsumer component so we should use consumer.delay 
      // as the URI parameter name. The FTP Component is an extension of 
      // the File Component.
         consumer.delay=" + delay).to("file://target/test-reports");

And the route using Spring DSL:

   <from uri="ftp://scott@localhost/public/reports?password=

   <to uri="file://target/test-reports"/>

Consuming a remote FTPS server (implicit SSL) and client authentication


Consuming a remote FTPS server (explicit TLS) and a custom trust store configuration


Filter using org.apache.camel.component.file.GenericFileFilter

Camel supports pluggable filtering strategies. This strategy it to use the built in org.apache.camel.component.file.GenericFileFilter in Java. You can then configure the endpoint with such a filter to skip certain filters before being processed.

In the sample we have build our own filter that only accepts files starting with report in the filename.

public class MyFileFilter implements GenericFileFilter {
   public boolean accept(GenericFile file) {
      // we only want report files 
      return file.getFileName().startsWith("report");

And then we can configure our route using the filter attribute to reference our filter (using # notation) that we have defined in the Spring XML file:

<!-- define our filter as a plain Spring bean -->
<bean id="myFilter" class="com.mycompany.MyFileFilter"/>

   <from uri="   //
   <to uri="bean:processInbox"/>

Filtering using ANT path matcher

The ANT path matcher is a filter that is shipped out-of-the-box in the camel-spring jar. So you need to depend on camel-spring if you are using Maven. The reason is that we leverage Spring's AntPathMatcher to do the matching.

The file paths are matched with the following rules:

  • ? matches one character

  • * matches zero or more characters

  • ** matches zero or more directories in a path

The sample below demonstrates how to use it:

<camelContext xmlns="">
   <template id="camelTemplate"/>
   <!-- use myFilter as filter to allow setting ANT paths for which -->
   <!-- filesto scan for -->
   <endpoint id="myFTPEndpoint" 

       <from ref="myFTPEndpoint"/>
       <to uri="mock:result"/>

<!-- we use the AntPathMatcherRemoteFileFilter to use ant paths for -->
<!-- includes and excludes -->
<bean id="myAntFilter" 
   <!-- include and file in the subfolder that has day in the name -->
   <property name="includes" value="**/subfolder/**/*day*"/>
   <!-- exclude all files with bad in name or .xml files. -->
   <!-- Use comma to separate multiple excludes -->
   <property name="excludes" value="**/*bad*,**/*.xml"/>

Using a proxy with SFTP

To use an HTTP proxy to connect to your remote host, you can configure your route in the following way:

<!-- define our sorter as a plain spring bean -->
<bean id="proxy" class="com.jcraft.jsch.ProxyHTTP">
  <constructor-arg value="localhost"/>
  <constructor-arg value="7777"/>
  <from uri="sftp://localhost:9999/root?username=admin&password=admin&proxy=#proxy"/>
  <to uri="bean:processFile"/>

You can also assign a user name and password to the proxy, if necessary. Please consult the documentation for com.jcraft.jsch.Proxy to discover all options.

Setting preferred SFTP authentication method

If you want to explicitly specify the list of authentication methods that should be used by sftp component, use preferredAuthentications option. If for example you would like Camel to attempt to authenticate with private/public SSH key and fallback to user/password authentication in the case when no public key is available, use the following route configuration:


Consuming a single file using a fixed name

When you want to download a single file and knows the file name, you can use fileName=myFileName.txt to tell Camel the name of the file to download. By default the consumer will still do a FTP LIST command to do a directory listing and then filter these files based on the fileName option. Though in this use-case it may be desirable to turn off the directory listing by setting useList=false. For example the user account used to login to the FTP server may not have permission to do a FTP LIST command. So you can turn off this with useList=false, and then provide the fixed name of the file to download with fileName=myFileName.txt, then the FTP consumer can still download the file. If the file for some reason does not exist, then Camel will by default throw an exception, you can turn this off and ignore this by setting ignoreFileNotFoundOrPermissionError=true.

For example to have a Camel route that pickup a single file, and delete it after use you can do


Notice that we have use all the options we talked above above.

You can also use this with ConsumerTemplate. For example to download a single file (if it exists) and grab the file content as a String type:

String data = template.retrieveBodyNoWait("ftp://admin@localhost:21/nolist/?
true&fileName=report.txt&delete=true", String.class);

Debug logging

This component has log level TRACE that can be helpful if you have problems.