This component supports FTP via the Jakarta Commons Net library.

Sending files over FTP

The default behaviour of sending files over FTP is for the message content to be the text which gets written into the file. For example this example..

InOnly exchange = client.createInOnlyExchange();
NormalizedMessage message = exchange.getInMessage();

message.setContent(new StringSource("<hello>world!</hello>"));

client.sendSync(exchange);

will generate an XML text file on the FTP server. Here is an example of the FTP configuration on the server side.

   <sm:activationSpec componentName="ftpSender" service="foo:ftpSender">
   	<sm:component><bean class="org.apache.servicemix.components.net.FTPSender">
    <property name="clientPool">
      <bean id="ftpClientPool" class="org.apache.servicemix.components.net.FTPClientPool">
        <property name="host" value="localhost"/>
        <property name="username" value="servicemix"/>
        <property name="password" value="rocks"/>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

Using properties to specify the file name or content

You can use properties on the message to override the destination file name and content. e.g.

InOnly exchange = client.createInOnlyExchange();
NormalizedMessage message = exchange.getInMessage();

message.setProperty("org.apache.servicemix.file.name", "cheese.txt");
message.setProperty("org.apache.servicemix.file.content", "Hello World!");

client.sendSync(exchange);

You can also use pluggable Expressions to configure the file name and/or file content.

If you do not specify a file name then a unique file name is created using a prefix you can specify (the uniqueFileName property).

<sm:activationSpec componentName="ftpSenderWithExpression" service="foo:ftpSenderWithExpression">
  <sm:component><bean class="org.apache.servicemix.components.net.FTPSender">
    <property name="clientPool">
      <bean id="ftpClientPool" class="org.apache.servicemix.components.net.FTPClientPool">
        <property name="host" value="localhost"/>
        <property name="username" value="servicemix"/>
        <property name="password" value="rocks"/>
      </bean>
    </property>

    <property name="marshaler">
      <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
        <property name="fileName">
          <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
            <constructor-arg value="concat('order_', order/@id, '.csv')"/>
          </bean>
        </property>
        <property name="content">
          <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
            <constructor-arg value="concat(/order/customer, ',', /order/value, ',', /order/@id)"/>
          </bean>
        </property>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

Polling for files

The FTPPoller will poll the server (with an optional path) for files on the FTP server then download them, fire them into the normalised message router and then delete them from the FTP server. Here's an example of this in action.

<sm:activationSpec componentName="ftpPoller" service="foo:ftpPoller" destinationService="foo:receiver">
  <sm:component><bean class="org.apache.servicemix.components.net.FTPPoller">
    <property name="clientPool" ref="ftpClientPool"/>
    <property name="workManager" ref="workManager"/>
    <!--
    <property name="path" value="foo"/>
    -->
    <property name="period" value="1000"/>
  </bean></sm:component>
</sm:activationSpec>