camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > FTP2
Date Mon, 29 Mar 2010 01:08:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/FTP2">FTP2</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~njiang">willem
jiang</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="FTP2-FTP%2FSFTP%2FFTPSComponentCamel2.0onwards"></a>FTP/SFTP/FTPS
Component - <b>Camel 2.0 onwards</b></h2>

<p>This component provides access to remote file systems over the FTP and SFTP protocols.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-cometd&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;

{info:title=Using Camel 1.x}
If you are using Camel 1.x then see <span class="code-keyword">this</span> [link|FTP]
<span class="code-keyword">for</span> documentation.
This page is only <span class="code-keyword">for</span> Camel 2.0 or newer.
{info}
{info:title=Using FTPS}
The FTPS component is only available in Camel 2.2 or newer.
FTPS (also known as FTP Secure) is an extension to FTP that adds support <span class="code-keyword">for</span>
the Transport Layer Security (TLS) and the Secure Sockets Layer (SSL) cryptographic protocols.
{info}

h3. URI format

</pre>
</div></div>
<p><a href="ftp://<span class="error">&#91;username@&#93;</span>hostname<a
href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=port&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">:port</a>/directoryname<a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=%3Foptions&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">&#63;options</a>" rel="nofollow">ftp://<span class="error">&#91;username@&#93;</span>hostname<a
href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=port&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">:port</a>/directoryname<a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=%3Foptions&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">&#63;options</a></a><br/>
sftp://<span class="error">&#91;username@&#93;</span>hostname<a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=port&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">:port</a>/directoryname<a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=%3Foptions&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">&#63;options</a>
<a href="ftps://<span class="error">&#91;username@&#93;</span>hostname<a
href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=port&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">:port</a>/directoryname<a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=%3Foptions&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">&#63;options</a>" rel="nofollow">ftps://<span class="error">&#91;username@&#93;</span>hostname<a
href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=port&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">:port</a>/directoryname<a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=%3Foptions&amp;linkCreation=true&amp;fromPageId=109470"
class="createlink">&#63;options</a></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">

Where *directoryname* represents the underlying directory. Can contain nested folders.
The *username* is currently only possible to provide in the hostname parameter.

If no *username* is provided, then {{anonymous}} login is attempted using no password.
If no *port* number is provided, Camel will provide <span class="code-keyword">default</span>
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&amp;option=value&amp;...}}

h3. URI Options
The options below are exclusive <span class="code-keyword">for</span> the [FTP2]
component. 
{div:class=confluenceTableSmall}
|| Name || Default Value || Description ||
| {{password}} | {{<span class="code-keyword">null</span>}} | Specifies the password
to use to log in to the remote file system. |
| {{binary}} | {{<span class="code-keyword">false</span>}} | Specifies the file
transfer mode, BINARY or ASCII. Default is ASCII ({{<span class="code-keyword">false</span>}}).
|
| {{disconnect}} | {{<span class="code-keyword">false</span>}} | *Camel 2.2:*
Whether or not to disconnect from remote FTP server right after use. Can be used <span
class="code-keyword">for</span> both consumer and producer. |
| {{localWorkDirectory}} | {{<span class="code-keyword">null</span>}} | 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, <span class="code-keyword">if</span>
you consume a very big remote file and thus can conserve memory. See below <span class="code-keyword">for</span>
more details. |
| {{passiveMode}} | {{<span class="code-keyword">false</span>}} | *FTP and FTPS
only*: Specifies whether to use passive mode connections. Default is active mode ({{<span
class="code-keyword">false</span>}}). |
| {{securityProtocol}} | {{TLS}} | *FTPS only:* Sets the underlying security protocol. The
following values are defined:\\
{{TLS}}: Transport Layer Security\\
{{SSL}}: Secure Sockets Layer |
| {{isImplicit}} | {{<span class="code-keyword">false</span>}} | *FTPS only:*
Sets the security mode(implicit/explicit). Default is explicit ({{<span class="code-keyword">false</span>}}).
|
| {{knownHostsFile}} | {{<span class="code-keyword">null</span>}} | *SFTP only:*
Sets the {{known_hosts}} file, so that the SFTP endpoint can <span class="code-keyword">do</span>
host key verification. |
| {{privateKeyFile}} | {{<span class="code-keyword">null</span>}} | *SFTP only:*
Set the <span class="code-keyword">private</span> key file to that the SFTP endpoint
can <span class="code-keyword">do</span> <span class="code-keyword">private</span>
key verification. |
| {{privateKeyFilePassphrase}} | {{<span class="code-keyword">null</span>}} |
*SFTP only:* Set the <span class="code-keyword">private</span> key file passphrase
to that the SFTP endpoint can <span class="code-keyword">do</span> <span class="code-keyword">private</span>
key verification. |
| {{strictHostKeyChecking}} | {{no}} | *SFTP only:* *Camel 2.2:* 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 <span class="code-keyword">for</span>
you as its meant <span class="code-keyword">for</span> human intervention. *Note:*
The <span class="code-keyword">default</span> in Camel 2.1 and below was {{ask}}.
|
| {{maximumReconnectAttempts}} | 3 | Specifies the maximum reconnect attempts Camel performs
when it tries to connect to the remote FTP server. Use 0 to disable <span class="code-keyword">this</span>
behavior. |
| {{reconnectDelay}} | 1000 | Delay in millis Camel will wait before performing a reconnect
attempt. |
| {{ftpClient}} | {{<span class="code-keyword">null</span>}} | *FTP and FTPS Only:*
*Camel 2.1:* Allows you to use a custom {{org.apache.commons.net.ftp.FTPClient}} instance.
|
| {{ftpClientConfig}} | {{<span class="code-keyword">null</span>}} | *FTP and
FTPS Only:* *Camel 2.1:* Allows you to use a custom {{org.apache.commons.net.ftp.FTPClientConfig}}
instance. |
| {{ftpClient.trustStore.file}} | {{<span class="code-keyword">null</span>}} |
*FTPS Only:* Sets the trust store file, so that the FTPS client can look up <span class="code-keyword">for</span>
trusted certificates. |
| {{ftpClient.trustStore.type}} | {{JKS}} | *FTPS Only:* Sets the trust store type. |
| {{ftpClient.trustStore.algorithm}} | {{SunX509}} | *FTPS Only:* Sets the trust store algorithm.
|
| {{ftpClient.trustStore.password}} | {{<span class="code-keyword">null</span>}}
| *FTPS Only:* Sets the trust store password. |
| {{ftpClient.keyStore.file}} | {{<span class="code-keyword">null</span>}} | *FTPS
Only:* Sets the key store file, so that the FTPS client can look up <span class="code-keyword">for</span>
the <span class="code-keyword">private</span> certificate. |
| {{ftpClient.keyStore.type}} | {{JKS}} | *FTPS Only:* Sets the key store type. |
| {{ftpClient.keyStore.algorithm}} | {{SunX509}} | *FTPS Only:* Sets the key store algorithm.
|
| {{ftpClient.keyStore.password}} | {{<span class="code-keyword">null</span>}}
| *FTPS Only:* Sets the key store password. |
| {{ftpClient.keyStore.keyPassword}} | {{<span class="code-keyword">null</span>}}
| *FTPS Only:* Sets the <span class="code-keyword">private</span> key password.
|

{div}

{info:title=FTPS component <span class="code-keyword">default</span> trust store}
By <span class="code-keyword">default</span>, the FTPS component trust store accept
all certificates. If you only want trust selective certificates, you have to configure the
trust store with the {{ftpClient.trustStore.xxx}} options or by configuring a custom {{ftpClient}}.
{info}

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 <span
class="code-keyword">do</span>:
</pre>
</div></div>
<p>from("ftp://foo@myserver?password=secret&amp;ftpClient.dataTimeout=30000").to("bean:foo");</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">

You can mix and match and have use both prefixes, <span class="code-keyword">for</span>
example to configure date format or timezones.
</pre>
</div></div>
<p>from("ftp://foo@myserver?password=secret&amp;ftpClient.dataTimeout=30000&amp;ftpClientConfig.serverLanguageCode=fr").to("bean:foo");</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">

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

See the documentation of the [Apache Commons FTP FTPClientConfig|http:<span class="code-comment">//commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClientConfig.html]
<span class="code-keyword">for</span> possible options and more details.
</span>And as well <span class="code-keyword">for</span> [Apache Commons
FTP FTPClient|http:<span class="code-comment">//commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html].
</span>
If you <span class="code-keyword">do</span> not like having many and <span
class="code-object">long</span> configuration in the url you can refer to the {{ftpClient}}
or {{ftpClientConfig}} to use by letting Camel lookup in the [Registry] <span class="code-keyword">for</span>
it.

For example:
</pre>
</div></div>
<p>   &lt;bean id="myConfig" class="org.apache.commons.net.ftp.FTPClientConfig"&gt;<br/>
       &lt;property name="lenientFutureDates" value="true"/&gt;<br/>
       &lt;property name="serverLanguageCode" value="fr"/&gt;<br/>
   &lt;/bean&gt;</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">

And then let Camel lookup <span class="code-keyword">this</span> bean when you
use the # notation in the url.
</pre>
</div></div>
<p>from("ftp://foo@myserver?password=secret&amp;ftpClientConfig=#myConfig").to("bean:foo");</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">


h3. More URI options
{info:title:More options}
See [File2] as all the options there also applies <span class="code-keyword">for</span>
<span class="code-keyword">this</span> component.
{info}

h4. Examples
{{ftp:<span class="code-comment">//someone@someftpserver.com/<span class="code-keyword">public</span>/upload/images/holiday2008?password=secret&amp;binary=<span
class="code-keyword">true</span>}}
</span>{{ftp:<span class="code-comment">//someoneelse@someotherftpserver.co.uk:12049/reports/2008/password=secret&amp;binary=<span
class="code-keyword">false</span>}}
</span>{{ftp:<span class="code-comment">//publicftpserver.com/download}}
</span>
{warning:title=FTP Consumer does not support concurrency}
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 <span class="code-keyword">this</span> issue,
it supports concurrency.

In the <span class="code-keyword">future</span> we will [add consumer pooling
to Camel|https:<span class="code-comment">//issues.apache.org/activemq/browse/CAMEL-1682]
to allow <span class="code-keyword">this</span> consumer to support concurrency
as well.
</span>{warning}

{tip:title=More information}
This component is an extension of the [File2] component. So there are more samples and details
on the [File2] component page.
{tip}

h3. Default when consuming files
The [FTP|FTP2] consumer will by <span class="code-keyword">default</span> leave
the consumed files untouched on the remote FTP server. You have to configure it explicit <span
class="code-keyword">if</span> you want it to delete the files or move them to another
location. For example you can use {{delete=<span class="code-keyword">true</span>}}
to delete the files, or use {{move=.done}} to move the files into a hidden done sub directory.

The regular [File|File2] consumer is different as it will by <span class="code-keyword">default</span>
move files to a {{.camel}} sub directory. The reason Camel does *not* <span class="code-keyword">do</span>
<span class="code-keyword">this</span> by <span class="code-keyword">default</span>
<span class="code-keyword">for</span> the FTP consumer is that it may lack permissions
by <span class="code-keyword">default</span> to be able to move or delete files.

h4. limitations
The option *readLock* can be used to force Camel *not* to consume files that is currently
in the progress of being written. However, <span class="code-keyword">this</span>
option is turned off by <span class="code-keyword">default</span>, as it requires
that the user has write access. There are other solutions to avoid consuming files that are
currently being written over FTP; <span class="code-keyword">for</span> instance,
you can write 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.

h3. Message Headers

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

|| Header || Description ||
| {{CamelFileName}} | Specifies the output file name (relative to the endpoint directory)
to be used <span class="code-keyword">for</span> the output message when sending
to the endpoint. If <span class="code-keyword">this</span> 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) <span class="code-keyword">for</span>
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. |
| {{CamelFileBatchIndex}} | Current index out of total number of files being consumed in <span
class="code-keyword">this</span> batch. |
| {{CamelFileBatchSize}} | Total number of files being consumed in <span class="code-keyword">this</span>
batch. |
| {{CamelFileHost}} | The remote hostname. |
| {{CamelFileLocalWorkPath}} | Path to the local work file, <span class="code-keyword">if</span>
local work directory is used. |

h3. 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 <span class="code-keyword">while</span> the file is being downloaded.
Afterwards, the file is renamed to remove the {{.inprogress}} suffix. And <span class="code-keyword">finally</span>,
when the [Exchange] is complete the local file is deleted. 

So <span class="code-keyword">if</span> 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:java}
from(<span class="code-quote">"ftp:<span class="code-comment">//someone@someserver.com?password=secret&amp;localWorkDirectory=/tmp"</span>).to(<span
class="code-quote">"file://inbox"</span>);</span>
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Optimization by renaming
work file</b><br /><p>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 <tt>java.io.File</tt> handle is then used as the <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> body. The file producer leverages this fact and can
work directly on the work file <tt>java.io.File</tt> handle and perform a <tt>java.io.File.rename</tt>
to the target filename. As Camel knows it's 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.</p></td></tr></table></div>

<h3><a name="FTP2-Samples"></a>Samples</h3>

<p>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.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder
createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span>
RouteBuilder() {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span>
Exception {
            <span class="code-comment">// we use a delay of 60 minutes (eg. once pr.
hour we poll the FTP server
</span>            <span class="code-object">long</span> delay = 60 * 60
* 1000L;

            <span class="code-comment">// from the given FTP server we poll (= download)
all the files
</span>            <span class="code-comment">// from the <span class="code-keyword">public</span>/reports
folder as BINARY types and store <span class="code-keyword">this</span> as files
</span>            <span class="code-comment">// in a local directory. Camel will
use the filenames from the FTPServer
</span>
            <span class="code-comment">// notice that the FTPConsumer properties must
be prefixed with <span class="code-quote">"consumer."</span> in the URL
</span>            <span class="code-comment">// the delay parameter is from the
FileConsumer component so we should use consumer.delay as
</span>            <span class="code-comment">// the URI parameter name. The FTP
Component is an extension of the File Component.
</span>            from(<span class="code-quote">"ftp:<span class="code-comment">//scott@localhost/<span
class="code-keyword">public</span>/reports?password=tiger&amp;binary=<span
class="code-keyword">true</span>&amp;consumer.delay="</span> + delay).
</span>                    to(<span class="code-quote">"file:<span class="code-comment">//target/test-reports"</span>);
</span>        }
    };
}
</pre>
</div></div>

<p>And the route using Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"ftp://scott@localhost/public/reports?password=tiger&amp;amp;binary=true&amp;amp;delay=60000"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"file://target/test-reports"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="FTP2-ConsumingaremoteFTPSserver%28implicitSSL%29andclientauthentication"></a>Consuming
a remote FTPS server (implicit SSL) and client authentication</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftps:<span class="code-comment">//admin@localhost:2222/<span
class="code-keyword">public</span>/camel?password=admin&amp;securityProtocol=SSL&amp;isImplicit=<span
class="code-keyword">true</span>&amp;ftpClient.keyStore.file=./src/test/resources/server.jks&amp;ftpClient.keyStore.password=password&amp;ftpClient.keyStore.keyPassword=password"</span>)
</span>  .to(<span class="code-quote">"bean:foo"</span>);
</pre>
</div></div>

<h4><a name="FTP2-ConsumingaremoteFTPSserver%28explicitTLS%29andacustomtruststoreconfiguration"></a>Consuming
a remote FTPS server (explicit TLS) and a custom trust store configuration</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftps:<span class="code-comment">//admin@localhost:2222/<span
class="code-keyword">public</span>/camel?password=admin&amp;ftpClient.trustStore.file=./src/test/resources/server.jks&amp;ftpClient.trustStore.password=password"</span>)
</span>  .to(<span class="code-quote">"bean:foo"</span>);
</pre>
</div></div>

<h3><a name="FTP2-Filterusing%7B%7Borg.apache.camel.component.file.GenericFileFilter%7D%7D"></a>Filter
using <tt>org.apache.camel.component.file.GenericFileFilter</tt></h3>
<p>Camel supports pluggable filtering strategies. This strategy it to use the build
in <tt>org.apache.camel.component.file.GenericFileFilter</tt> in Java. You can
then configure the endpoint with such a filter to skip certain filters before being processed.</p>

<p>In the sample we have build our own filter that only accepts files starting with
report in the filename.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyFileFilter
<span class="code-keyword">implements</span> GenericFileFilter {

    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
accept(GenericFile file) {
        <span class="code-comment">// we only want report files 
</span>        <span class="code-keyword">return</span> file.getFileName().startsWith(<span
class="code-quote">"report"</span>);
    }
}
</pre>
</div></div>

<p>And then we can configure our route using the <b>filter</b> attribute
to reference our filter (using <tt>&#35;</tt> notation) that we have defines
in the spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag"><span class="code-comment">&lt;!-- define our sorter
as a plain spring bean --&gt;</span></span>
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myFilter"</span>
class=<span class="code-quote">"com.mycompany.MyFileFilter"</span>/&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"ftp://someuser@someftpserver.com?password=secret&amp;amp;filter=#myFilter"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processInbox"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>


<h3><a name="FTP2-FilteringusingANTpathmatcher"></a>Filtering using ANT
path matcher</h3>
<p>The ANT path matcher is a filter that is shipped out-of-the-box in the <b>camel-spring</b>
jar. So you need to depend on <b>camel-spring</b> if you are using Maven.<br/>
The reason is that we leverage Spring's <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html"
rel="nofollow">AntPathMatcher</a> to do the actual matching.</p>

<p>The file paths are matched with the following rules:</p>
<ul class="alternate" type="square">
	<li><tt>?</tt> matches one character</li>
	<li><tt>*</tt> matches zero or more characters</li>
	<li><tt>**</tt> matches zero or more directories in a path</li>
</ul>


<p>The sample below demonstrates how to use it:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span
class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;template id=<span class="code-quote">"camelTemplate"</span>/&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- use myFilter
as filter to allow setting ANT paths for which files to scan for --&gt;</span></span>
    <span class="code-tag">&lt;endpoint id=<span class="code-quote">"myFTPEndpoint"</span>
uri=<span class="code-quote">"ftp://admin@localhost:20123/antpath?password=admin&amp;amp;recursive=true&amp;amp;delay=10000&amp;amp;initialDelay=2000&amp;amp;filter=#myAntFilter"</span>/&gt;</span>

    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from ref=<span class="code-quote">"myFTPEndpoint"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- we use the AntPathMatcherRemoteFileFilter
to use ant paths for includes and exlucde --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"myAntFilter"</span>
class=<span class="code-quote">"org.apache.camel.component.file.AntPathMatcherGenericFileFilter"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- include and
file in the subfolder that has day in the name --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"includes"</span>
value=<span class="code-quote">"**/subfolder/**/*day*"</span>/&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- exclude all
files with bad in name or .xml files. Use comma to seperate multiple excludes --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"excludes"</span>
value=<span class="code-quote">"**/*bad*,**/*.xml"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="FTP2-Debuglogging"></a>Debug logging</h3>
<p>This component has log level <b>TRACE</b> that can be helpful if you
have problems.</p>

<h3><a name="FTP2-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/File2" title="File2">File2</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/FTP2">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=109470&revisedVersion=32&originalVersion=31">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/FTP2?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message