FTP/SFTP — provides access to remote file systems over the FTP and SFTP protocols
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.
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
Table 13, “FTP options” lists the options for the FTP component.
Table 13. FTP options
Name | Supported Protocol | Default Value | Description |
---|---|---|---|
password | FTP, FTPS, SFTP | null
| Specifies the password to use to log in to the remote file system. |
binary | FTP, FTPS, SFTP | false | Specifies the if the files should be treated as binary data. |
disconnect | FTP, FTPS, SFTP | 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. |
localWorkDirectory | FTP, FTPS, SFTP | null
| 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. |
passiveMode | FTP | false | Specifies whether to use passive mode connections. |
securityProtocol | FTPS | TLS |
Sets the underlying security protocol.
The following values are defined: |
disableSecureDataChannelDefaults | FTPS | false | 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. |
execProt | FTPS | null
|
Will by default use option
|
execPbsz | FTPS | null | 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. |
isImplicit | FTPS | false
| Specifies if the security mode is implicit. |
knownHostsFile | SFTP | null
| Sets the known_hosts
file, so that the SFTP endpoint can do host key verification. |
privateKeyFilePassphrase | SFTP | null
| Set the private key file passphrase to that the SFTP endpoint can do private key verification. |
privateKeyFilePassphrase | SFTP | null
| Set the private key file passphrase to that the SFTP endpoint can do private key verification. |
strictHostKeyChecking | SFTP | no
| 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. |
maximumReconnectAttempts | FTP, FTPS, SFTP | 3 | Specifies the maximum reconnect attempts Apache Camel performs when it tries to connect to the remote FTP server. Use 0 to disable this behavior. |
reconnectDelay | FTP, FTPS, SFTP | 1000 | Delay in milliseconds Apache Camel will wait before performing a reconnect attempt. |
connectTimeout | FTP, FTPS, SFTP | 10000 | Specifies the connect timeout in milliseconds. |
soTimeout | FTP, FTPS | null | Specifies the SocketOptions.SO_TIMEOUT value in
milliseconds. |
timeout | FTP, FTPS | 30000 | Specifies the data timeout in milliseconds. |
throwExceptionOnConnectFailed | FTP, FTPS, SFTP | false | Specifies 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. |
siteCommand | FTP, FTPS | null
| 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. |
stepwise | FTP, FTPS, SFTP | true | When 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. |
ftpClient | FTP, FTPS | null | Allows you to use a custom
org.apache.commons.net.ftp.FTPClient instance. |
ftpClientConfig | FTP, FTPS | null | Allows you to use a custom
org.apache.commons.net.ftp.FTPClientConfig instance. |
ftpClient.trustStore.file | FTPS | null | Sets the trust store file, so that the FTPS client can look up for trusted certificates. |
ftpClient.trustStore.type | FTPS | JKS | Sets the trust store type. |
ftpClient.trustStore.algorithm | FTPS | SunX509 | Sets the trust store algorithm. |
ftpClient.trustStore.password | FTPS | null | Sets the trust store password. |
ftpClient.keyStore.file | FTPS | null
| Sets the key store file, so that the FTPS client can look up for the private certificate. |
ftpClient.keyStore.type
| FTPS | JKS
| Sets the key store type. |
ftpClient.keyStore.algorithm
| FTPS | SunX509
| Sets the key store algorithm. |
ftpClient.keyStore.password
| FTPS | null
| Sets the key store password. |
ftpClient.keyStore.keyPassword
| FTPS | null
| Sets the private key password. |
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.
Many of the file endpoint options also apply to the FTP/SFTP endpoints. See File.
The following message headers can be used to affect the behavior of the component:
Table 14. FTP message headers
Header | Description |
---|---|
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. |