Name

FTP/SFTP — provides access to remote file systems over the FTP and SFTP protocols

Overview

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

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

URI format

The URI format for an FTP endpoint is:

ftp://[username@]hostname[:port]/directoryname[?options]
ftps://[username@]hostname[:port]/directoryname[?options]

The URI format for an SFTP endpoint is:

sftp://[username@]hostname[:port]/directoryname[?options]

If no username is provided, then an anonymous login is attempted.

If no port number is provided, Apache Camel will provide default values according to the protocol:

  • ftp = 21

  • sftp = 22

  • ftps = 21

Options

Table 13, “FTP options” lists the options for the FTP component.

Table 13. FTP options

NameSupported ProtocolDefault ValueDescription
passwordFTP, FTPS, SFTPnull Specifies the password to use to log in to the remote file system.
binaryFTP, FTPS, SFTPfalseSpecifies the if the files should be treated as binary data.
disconnectFTP, FTPS, SFTPfalseWhether 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.
localWorkDirectoryFTP, FTPS, SFTPnull 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.
passiveModeFTPfalseSpecifies whether to use passive mode connections.
securityProtocolFTPSTLS

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

disableSecureDataChannelDefaultsFTPSfalseWhether 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.
execProtFTPSnull

Will by default use option P 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

execPbszFTPSnullThis 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.
isImplicitFTPSfalse Specifies if the security mode is implicit.
knownHostsFileSFTPnull Sets the known_hosts file, so that the SFTP endpoint can do host key verification.
privateKeyFilePassphraseSFTPnull Set the private key file passphrase to that the SFTP endpoint can do private key verification.
privateKeyFilePassphraseSFTPnull Set the private key file passphrase to that the SFTP endpoint can do private key verification.
strictHostKeyCheckingSFTPno Sets whether to use strict host key checking. Possible values are: no, yes and ask. ask does not make sense to use as Camel cannot answer the question for you as its meant for human intervention.
maximumReconnectAttemptsFTP, FTPS, SFTP3 Specifies the maximum reconnect attempts Apache Camel performs when it tries to connect to the remote FTP server. Use 0 to disable this behavior.
reconnectDelayFTP, FTPS, SFTP 1000 Delay in milliseconds Apache Camel will wait before performing a reconnect attempt.
connectTimeoutFTP, FTPS, SFTP10000Specifies the connect timeout in milliseconds.
soTimeoutFTP, FTPSnullSpecifies the SocketOptions.SO_TIMEOUT value in milliseconds.
timeoutFTP, FTPS30000Specifies the data timeout in milliseconds.
throwExceptionOnConnectFailedFTP, FTPS, SFTPfalseSpecifies whether or not to thrown an exception if a successful connection and login could not be establish. This allows a custom pollStrategy to deal with the exception, for example to stop the consumer or the likes.
siteCommandFTP, FTPSnull 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.
stepwiseFTP, FTPS, SFTPtrueWhen consuming directories, specifies whether or not to use stepwise mode for traversing the directory tree. Stepwise means that it will CD one directory at a time.
ftpClientFTP, FTPSnullAllows you to use a custom org.apache.commons.net.ftp.FTPClient instance.
ftpClientConfigFTP, FTPSnullAllows you to use a custom org.apache.commons.net.ftp.FTPClientConfig instance.
ftpClient.trustStore.fileFTPSnullSets the trust store file, so that the FTPS client can look up for trusted certificates.
ftpClient.trustStore.typeFTPSJKSSets the trust store type.
ftpClient.trustStore.algorithmFTPSSunX509Sets the trust store algorithm.
ftpClient.trustStore.passwordFTPSnullSets the trust store password.
ftpClient.keyStore.fileFTPSnull Sets the key store file, so that the FTPS client can look up for the private certificate.
ftpClient.keyStore.type FTPSJKS Sets the key store type.
ftpClient.keyStore.algorithm FTPSSunX509 Sets the key store algorithm.
ftpClient.keyStore.password FTPSnull Sets the key store password.
ftpClient.keyStore.keyPassword FTPSnull Sets the private key password.

Apache Commons FTP options

The FTP and FTPS protocols can support additional configuration options provided by the Apache Commons FTP layer used to implement them. To specify these additional options you use the ftpClient. or ftpClientConfig. prefix. The prefixes correspond to the Apache Commons FTPClient and the Apache Commons FTPClientConfig objects.

If you do not like having many and long configuration in the URL you can configure the ftpClient or the ftpClientConfig in the Spring configuration as shown in Example 4, “Configuring the FTP client in XML”.

Example 4. Configuring the FTP client in XML

<bean id="myConfig" class="org.apache.commons.net.ftp.FTPClientConfig">
  <property name="lenientFutureDates" value="true"/>
  <property name="serverLanguageCode" value="fr"/>
</bean>
...
<camelContext>
  <route id="myroute">
    <from uri="ftp://foo@myserver?password=secret&ftpClientConfig=#myConfig" />
    <to uri="bean:foo" />
  </route>
  ...
</camelContext>
...

See the documentation of the Apache Commons FTP FTPClientConfig for possible options and more details. And as well for Apache Commons FTP FTPClient.

File endpoint options

Many of the file endpoint options also apply to the FTP/SFTP endpoints. See File.

Message headers

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

Table 14. FTP message headers

HeaderDescription
CamelFileName Specifies the output file name (relative to the endpoint directory) to be used for the output message when sending to the endpoint. If this is not present and no expression either, then a generated message ID is used as the filename instead.
CamelFileNameProduced The actual absolute filepath (path + name) for the output file that was written. This header is set by Apache Camel and its purpose is providing end-users the name of the file that was written.
CamelFileBatchIndex Current index out of total number of files being consumed in this batch.
CamelFileBatchSize Total number of files being consumed in this batch.
CamelFileHost The remote hostname.
CamelFileLocalWorkPath Path to the local work file, if local work directory is used.

Related topics

File
Apache Commons Net
Apache Commons FTP FTPClientConfig
Apache Commons FTP FTPClient
JCraft JSCH