...
Maven users will need to add the following dependency to their pom.xml
for this component:
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
|
...
Tip | ||
---|---|---|
| ||
Make sure you read the section titled Default when consuming files further below for details related to consuming files. |
URI format
Code Block |
---|
ftp://[username@]hostname[:port]/directoryname[?options]
sftp://[username@]hostname[:port]/directoryname[?options]
ftps://[username@]hostname[:port]/directoryname[?options]
|
...
Div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Info | ||
---|---|---|
| ||
When using the When using |
...
For example to set the setDataTimeout
on the FTPClient
to 30 seconds you can do:
Code Block |
---|
from("ftp://foo@myserver?password=secret&ftpClient.dataTimeout=30000").to("bean:foo");
|
You can mix and match and have use both prefixes, for example to configure date format or timezones.
Code Block |
---|
from("ftp://foo@myserver?password=secret&ftpClient.dataTimeout=30000&ftpClientConfig.serverLanguageCode=fr").to("bean:foo");
|
...
If you do not like having many and long configuration in the url you can refer to the ftpClient
or ftpClientConfig
to use by letting Camel lookup in the Registry for it.
For example:
Code Block |
---|
<bean id="myConfig" class="org.apache.commons.net.ftp.FTPClientConfig">
<property name="lenientFutureDates" value="true"/>
<property name="serverLanguageCode" value="fr"/>
</bean>
|
And then let Camel lookup this bean when you use the # notation in the url.
Code Block |
---|
from("ftp://foo@myserver?password=secret&ftpClientConfig=#myConfig").to("bean:foo");
|
...
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:
Code Block | ||||
---|---|---|---|---|
| ||||
from("ftp://someone@someserver.com?password=secret&localWorkDirectory=/tmp").to("file://inbox");
|
...
The difference between the two of them is best illustrated with an example. Suppose we have the following directory structure on the remote FTP server we need to traverse and download files:
Code Block |
---|
/
/one
/one/two
/one/two/sub-a
/one/two/sub-b
|
...
Using stepwise=true (default mode)
Code Block |
---|
TYPE A
200 Type set to A
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
SYST
215 UNIX emulated by FileZilla
PORT 127,0,0,1,17,94
200 Port command successful
LIST
150 Opening data channel for directory list.
226 Transfer OK
CWD sub-a
250 CWD successful. "/one/two/sub-a" is current directory.
PORT 127,0,0,1,17,95
200 Port command successful
LIST
150 Opening data channel for directory list.
226 Transfer OK
CDUP
200 CDUP successful. "/one/two" is current directory.
CWD sub-b
250 CWD successful. "/one/two/sub-b" is current directory.
PORT 127,0,0,1,17,96
200 Port command successful
LIST
150 Opening data channel for directory list.
226 Transfer OK
CDUP
200 CDUP successful. "/one/two" is current directory.
CWD /
250 CWD successful. "/" is current directory.
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
PORT 127,0,0,1,17,97
200 Port command successful
RETR foo.txt
150 Opening data channel for file transfer.
226 Transfer OK
CWD /
250 CWD successful. "/" is current directory.
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
CWD sub-a
250 CWD successful. "/one/two/sub-a" is current directory.
PORT 127,0,0,1,17,98
200 Port command successful
RETR a.txt
150 Opening data channel for file transfer.
226 Transfer OK
CWD /
250 CWD successful. "/" is current directory.
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
CWD sub-b
250 CWD successful. "/one/two/sub-b" is current directory.
PORT 127,0,0,1,17,99
200 Port command successful
RETR b.txt
150 Opening data channel for file transfer.
226 Transfer OK
CWD /
250 CWD successful. "/" is current directory.
QUIT
221 Goodbye
disconnected.
|
...
Using stepwise=false
Code Block |
---|
230 Logged on
TYPE A
200 Type set to A
SYST
215 UNIX emulated by FileZilla
PORT 127,0,0,1,4,122
200 Port command successful
LIST one/two
150 Opening data channel for directory list
226 Transfer OK
PORT 127,0,0,1,4,123
200 Port command successful
LIST one/two/sub-a
150 Opening data channel for directory list
226 Transfer OK
PORT 127,0,0,1,4,124
200 Port command successful
LIST one/two/sub-b
150 Opening data channel for directory list
226 Transfer OK
PORT 127,0,0,1,4,125
200 Port command successful
RETR one/two/foo.txt
150 Opening data channel for file transfer.
226 Transfer OK
PORT 127,0,0,1,4,126
200 Port command successful
RETR one/two/sub-a/a.txt
150 Opening data channel for file transfer.
226 Transfer OK
PORT 127,0,0,1,4,127
200 Port command successful
RETR one/two/sub-b/b.txt
150 Opening data channel for file transfer.
226 Transfer OK
QUIT
221 Goodbye
disconnected.
|
...
And the route using Spring DSL:
Code Block | ||||
---|---|---|---|---|
| ||||
<route>
<from uri="ftp://scott@localhost/public/reports?password=tiger&binary=true&delay=60000"/>
<to uri="file://target/test-reports"/>
</route>
|
Consuming a remote FTPS server (implicit SSL) and client authentication
Code Block |
---|
from("ftps://admin@localhost:2222/public/camel?password=admin&securityProtocol=SSL&isImplicit=true
&ftpClient.keyStore.file=./src/test/resources/server.jks
&ftpClient.keyStore.password=password&ftpClient.keyStore.keyPassword=password")
.to("bean:foo");
|
Consuming a remote FTPS server (explicit TLS) and a custom trust store configuration
Code Block |
---|
from("ftps://admin@localhost:2222/public/camel?password=admin&ftpClient.trustStore.file=./src/test/resources/server.jks&ftpClient.trustStore.password=password")
.to("bean:foo");
|
...
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:
Code Block | ||||
---|---|---|---|---|
| ||||
<!-- define our sorter as a plain spring bean -->
<bean id="myFilter" class="com.mycompany.MyFileFilter"/>
<route>
<from uri="ftp://someuser@someftpserver.com?password=secret&filter=#myFilter"/>
<to uri="bean:processInbox"/>
</route>
|
...
To use an HTTP proxy to connect to your remote host, you can configure your route in the following way:
Code Block | ||||
---|---|---|---|---|
| ||||
<!-- define our sorter as a plain spring bean -->
<bean id="proxy" class="com.jcraft.jsch.ProxyHTTP">
<constructor-arg value="localhost"/>
<constructor-arg value="7777"/>
</bean>
<route>
<from uri="sftp://localhost:9999/root?username=admin&password=admin&proxy=#proxy"/>
<to uri="bean:processFile"/>
</route>
|
...
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:
Code Block |
---|
from("sftp://localhost:9999/root?username=admin&password=admin&preferredAuthentications=publickey,password").
to("bean:processFile");
|
...
For example to have a Camel route that pickup a single file, and delete it after use you can do
Code Block |
---|
from("ftp://admin@localhost:21/nolist/?password=admin&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=report.txt&delete=true")
.to("activemq:queue:report");
|
...
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:
Code Block |
---|
String data = template.retrieveBodyNoWait("ftp://admin@localhost:21/nolist/?password=admin&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=report.txt&delete=true", String.class);
|
...
This component has log level TRACE that can be helpful if you have problems.
Include Page | ||||
---|---|---|---|---|
|