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 Sat, 18 Jul 2009 06:05: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/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="FTP2-FTP%2FSFTPComponentCamel2.0onwards"></a>FTP/SFTP
Component - <b>Camel 2.0 onwards</b></h2>

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

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Using Camel
1.x</b><br /><p>If you are using Camel 1.x then see this <a href="/confluence/display/CAMEL/FTP"
title="FTP">link</a> for documentation.<br/>
This page is only for Camel 2.0 or newer.</p></td></tr></table></div>

<h3><a name="FTP2-URIformat"></a>URI format</h3>

<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">ftp://[username@]hostname[:port]/directoryname[?options]
sftp://[username@]hostname[:port]/directoryname[?options]</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Where <b>directoryname</b> represents the underlying directory. Can contain
nested folders.<br/>
The <b>username</b> is currently only possible to provide in the hostname parameter.</p>

<p>If no <b>username</b> is provided, then <tt>anonymous</tt>
login is attempted using no password.<br/>
If no <b>port</b> number is provided, Camel will provide default values according
to the protocol (ftp = 21, sftp = 22).</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="FTP2-URIOptions"></a>URI Options</h3>
<p>The options below are exclusive for the <a href="/confluence/display/CAMEL/FTP2"
title="FTP2">FTP2</a> component. </p>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the password to use to log in to the remote file
system. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>binary</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies the file transfer mode, BINARY or ASCII. Default
is ASCII (<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>localWorkDirectory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>passiveMode</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>FTP only</b>: Specifies whether to use passive
mode connections. Default is active mode {<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClientConfig</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP only</b>: Reference to a bean in the registry
as a <tt><a href="http://commons.apache.org/net/apidocs/org/apache/commons/net/ftp/FTPClientConfig.html"
rel="nofollow">org.apache.commons.net.ftp.FTPClientConfig</a></tt> class. Use
this option if you need to configure the client according to the FTP Server date format, locale,
timezone, platform etc. See the javadoc <tt><a href="http://commons.apache.org/net/apidocs/org/apache/commons/net/ftp/FTPClientConfig.html"
rel="nofollow">FTPClientConfig</a></tt> for more documentation.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>knownHostsFile</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> Sets the <tt>known_hosts</tt>
file, so that the SFTP endpoint can do host key verification. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>privateKeyFile</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> Set the private key file to
that the SFTP endpoint can do private key verification. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>privateKeyFilePassphrase</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> Set the private key file passphrase
to that the SFTP endpoint can do private key verification. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maximumReconnectAttempts</tt> </td>
<td class='confluenceTd'> 3 </td>
<td class='confluenceTd'> Specifies the maximum reconnect attempts Camel performs when
it tries to connect to the remote FTP server. Use 0 to disable this behavior. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reconnectDelay</tt> </td>
<td class='confluenceTd'> 1000 </td>
<td class='confluenceTd'> Delay in millis Camel will wait before performing a reconnect
attempt. </td>
</tr>
</tbody></table>
</div>

<h3><a name="FTP2-MoreURIoptions"></a>More URI options</h3>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><p>See <a
href="/confluence/display/CAMEL/File2" title="File2">File2</a> as all the options
there also applies for this component.</p></td></tr></table></div>

<h4><a name="FTP2-Examples"></a>Examples</h4>
<p><tt><a href="ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&amp;binary=true"
rel="nofollow">ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&amp;binary=true</a></tt><br/>
<tt><a href="ftp://someoneelse@someotherftpserver.co.uk:12049/reports/2008/password=secret&amp;binary=false"
rel="nofollow">ftp://someoneelse@someotherftpserver.co.uk:12049/reports/2008/password=secret&amp;binary=false</a></tt><br/>
<tt><a href="ftp://publicftpserver.com/download" rel="nofollow">ftp://publicftpserver.com/download</a></tt></p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>FTP Consumer
does not support concurrency</b><br /><p>The FTP consumer (with the same
endpoint) does not support concurrency (the backing FTP client is not thread safe).<br/>
You can use multiple FTP consumers to poll from different endpoints. It is only a single endpoint
that does not support concurrent consumers.</p>

<p>The FTP producer does <b>not</b> have this issue, it supports concurrency.</p>

<p>In the future we will <a href="https://issues.apache.org/activemq/browse/CAMEL-1682"
rel="nofollow">add consumer pooling to Camel</a> to allow this consumer to support
concurrency as well.</p></td></tr></table></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>More information</b><br
/><p>This component is an extension of the <a href="/confluence/display/CAMEL/File2"
title="File2">File2</a> component. So there are more samples and details on the <a
href="/confluence/display/CAMEL/File2" title="File2">File2</a> component page.</p></td></tr></table></div>

<h4><a name="FTP2-limitations"></a>limitations</h4>
<p>The option <b>readLock</b> can be used to force Camel <b>not</b>
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 other solutions
to avoid consuming files that are currently being written over FTP; for instance, you can
write to a temporary destination and move the file after it has been written. </p>

<p>The ftp producer does <b>not</b> support appending to existing files.
Any existing files on the remote server will be deleted before the file is written.</p>

<h3><a name="FTP2-MessageHeaders"></a>Message Headers</h3>

<p>The following message headers can be used to affect the behavior of the component</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileName</tt> </td>
<td class='confluenceTd'> 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.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileNameProduced</tt> </td>
<td class='confluenceTd'> The actual 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileBatchIndex</tt> </td>
<td class='confluenceTd'> Current index out of total number of files being consumed
in this batch. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileBatchSize</tt> </td>
<td class='confluenceTd'> Total number of files being consumed in this batch. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileHost</tt> </td>
<td class='confluenceTd'> The remote hostname. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileLocalWorkPath</tt> </td>
<td class='confluenceTd'> Path to the local work file, if local work directory is used.
</td>
</tr>
</tbody></table>

<h3><a name="FTP2-UsingLocalWorkDirectory"></a>Using Local Work Directory</h3>
<p>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 <tt>FileOutputStream</tt>.
</p>

<p>Camel will store to a local file with the same name as the remote file, though with
<tt>.progress</tt> as extension while the file is being downloaded. Afterwards,
the file is renamed to remove the <tt>.inprogress</tt> suffix. And finally, when
the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
is complete the local file is deleted. </p>

<p>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:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("ftp://someone@someserver.com?password=secret&amp;localWorkDirectory=/tmp").to("file://inbox");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">protected
RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // we use a delay of 60 minutes (eg. once pr. 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.
            from("ftp://scott@localhost/public/reports?password=tiger&amp;binary=true&amp;consumer.delay="
+ delay).
                    to("file://target/test-reports");
        }
    };
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And the route using Spring DSL:</p>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;route&gt;
     &lt;from uri="ftp://scott@localhost/public/reports?password=tiger&amp;amp;binary=true&amp;amp;delay=60000"/&gt;
     &lt;to uri="file://target/test-reports"/&gt;
  &lt;/route&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="FTP2-ConsumingaremoteFTPservertriggeredbyaroute"></a>Consuming
a remote FTP server triggered by a route</h4>
<p>The FTP consumer is built as a scheduled consumer to be used in the <b>from</b>
route. However, if you want to start consuming from an FTP server triggered within a route,
it's a bit cumbersome to do this in Camel 1.x as opposed to Camel 2.0 where its supported
directly in the DSL. However it's possible to do so in Camel 1.x, as this code below demonstrates.</p>

<h5><a name="FTP2-Camel1.x"></a>Camel 1.x</h5>
<p><span class="error">Unable to render content due to system error: Hibernate
operation: could not insert: [com.atlassian.confluence.pages.Page#2327381]; SQL []; Duplicate
entry &#39;2327381&#39; for key 1; nested exception is com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Duplicate entry &#39;2327381&#39; for key 1</span></p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">//
we use delay=5000 to use 5 sec delay between pools to avoid polling a second time before we
stop the consumer
// this is because we only want to run a single poll and get the file
private String getFtpUrl() {
    return "ftp://admin@localhost:" + getPort() + "/getme?password=admin&amp;binary=false&amp;delay=5000";
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And then we have the route where we use a <a href="/confluence/display/CAMEL/Processor"
title="Processor">Processor</a> within the route, so we can use Java code. In this
Java code, we create the ftp consumer that downloads the file we want. And after the download
we can get the content of the file and put it in the original exchange that continues being
routed. As this is based on an unit test it routes to a <a href="/confluence/display/CAMEL/Mock"
title="Mock">Mock</a> endpoint.</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("seda:start").process(new
Processor() {
    public void process(final Exchange exchange) throws Exception {
        // get the filename from our custome header we want to get from a remote server
        String filename = exchange.getIn().getHeader("myfile", String.class);

        // construct the total url for the ftp consumer
        // add the fileName option with the file we want to consume
        String url = getFtpUrl() + "&amp;fileName=" + filename;

        // create a ftp endpoint
        Endpoint ftp = context.getEndpoint(url);

        // create a polling consumer where we can poll the myfile from the ftp server
        PollingConsumer consumer = ftp.createPollingConsumer();

        // must start the consumer before we can receive
        consumer.start();

        // poll the file from the ftp server
        Exchange result = consumer.receive();

        // the result is the response from the FTP consumer (the downloaded file)
        // replace the outher exchange with the content from the downloaded file
        exchange.getIn().setBody(result.getIn().getBody());

        // stop the consumer
        consumer.stop();
    }
}).to("mock:result");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h5><a name="FTP2-Camel2.0"></a>Camel 2.0</h5>
<p>The same sample would be like this in Camel 2.0 where we can use the <a href="/confluence/display/CAMEL/Content+Enricher"
title="Content Enricher">Content Enricher</a> EIP with the <tt>pollEnrich</tt>
DSL:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("seda:start")
   // set the filename in FILE_NAME header so Camel know the name of the remote file to poll
   .setHeader(Exchange.FILE_NAME, header("myfile"))
   .pollEnrich("ftp://admin@localhost:21/getme?password=admin&amp;binary=false")
   .to("mock:result");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">public
class MyFileFilter implements GenericFileFilter {

    public boolean accept(GenericFile file) {
        // we only want report files 
        return file.getFileName().startsWith("report");
    }
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;!--
define our sorter as a plain spring bean --&gt;
   &lt;bean id="myFilter" class="com.mycompany.MyFileFilter"/&gt;

  &lt;route&gt;
    &lt;from uri="ftp://someuser@someftpserver.com?password=secret&amp;amp;filter=#myFilter"/&gt;
    &lt;to uri="bean:processInbox"/&gt;
  &lt;/route&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;camelContext
xmlns="http://camel.apache.org/schema/spring"&gt;
    &lt;template id="camelTemplate"/&gt;

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

    &lt;route&gt;
        &lt;from ref="myFTPEndpoint"/&gt;
        &lt;to uri="mock:result"/&gt;
    &lt;/route&gt;
&lt;/camelContext&gt;

&lt;!-- we use the AntPathMatcherRemoteFileFilter to use ant paths for includes and exlucde
--&gt;
&lt;bean id="myAntFilter" class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter"&gt;
    &lt;!-- include and file in the subfolder that has day in the name --&gt;
    &lt;property name="includes" value="**/subfolder/**/*day*"/&gt;
    &lt;!-- exclude all files with bad in name or .xml files. Use comma to seperate multiple
excludes --&gt;
    &lt;property name="excludes" value="**/*bad*,**/*.xml"/&gt;
&lt;/bean&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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=17&originalVersion=16">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