This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Integration 7.1.1!

FTP Session Factory

Spring Integration provides factories you can use to create FTP (or FTPS) sessions.

Default Factories

Starting with version 3.0, sessions are no longer cached by default. See FTP Session Caching.

Before configuring FTP adapters, you must configure an FTP session factory. You can configure the FTP Session Factory with a regular bean definition where the implementation class is o.s.i.ftp.session.DefaultFtpSessionFactory. The following example shows a basic configuration:

<bean id="ftpClientFactory"
    class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="localhost"/>
    <property name="port" value="22"/>
    <property name="username" value="kermit"/>
    <property name="password" value="frog"/>
    <property name="clientMode" value="0"/>
    <property name="fileType" value="2"/>
    <property name="bufferSize" value="100000"/>
</bean>

For FTPS connections, you can use o.s.i.ftp.session.DefaultFtpsSessionFactory instead.

The following example shows a complete configuration:

<bean id="ftpClientFactory"
    class="org.springframework.integration.ftp.session.DefaultFtpsSessionFactory">
    <property name="host" value="localhost"/>
    <property name="port" value="22"/>
    <property name="username" value="oleg"/>
    <property name="password" value="password"/>
    <property name="clientMode" value="1"/>
    <property name="fileType" value="2"/>
    <property name="useClientMode" value="true"/>
    <property name="cipherSuites" value="a,b.c"/>
    <property name="keyManager" ref="keyManager"/>
    <property name="protocol" value="SSL"/>
    <property name="trustManager" ref="trustManager"/>
    <property name="prot" value="P"/>
    <property name="needClientAuth" value="true"/>
    <property name="authValue" value="oleg"/>
    <property name="sessionCreation" value="true"/>
    <property name="protocols" value="SSL, TLS"/>
    <property name="implicit" value="true"/>
</bean>
If you experience connectivity problems and would like to trace session creation as well as see which sessions are polled, you can enable session tracing by setting the logger to the TRACE level (for example, log4j.category.org.springframework.integration.file=TRACE).

Now you need only inject these session factories into your adapters. The protocol (FTP or FTPS) that an adapter uses depends on the type of session factory that has been injected into the adapter.

A more practical way to provide values for FTP or FTPS session factories is to use Spring’s property placeholder support (See docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-placeholderconfigurer).

Proxy Support

Starting with version 7.2, the session factories can connect to the FTP (or FTPS) server through a proxy.

The proxy property of the AbstractFtpSessionFactory (and, therefore, of the DefaultFtpSessionFactory and the DefaultFtpsSessionFactory) accepts a java.net.Proxy. The proxy is used for the control connection and for the data connections, which requires the passive client mode (FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE): the server cannot connect back to the client through a proxy. Therefore, setting the proxy also switches the clientMode to the passive mode. If the clientMode is changed afterwards to another mode, the session factory fails to create a session. A Proxy.Type.SOCKS proxy is used as is. A Proxy.Type.HTTP proxy is used with the HTTP CONNECT tunneling of the JVM; the credentials for such a proxy, if any, have to be provided through a java.net.Authenticator.

The following example shows a session factory that connects through a SOCKS proxy:

@Bean
DefaultFtpSessionFactory ftpSessionFactory() {
    DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
    sessionFactory.setHost("ftp.example.com");
    sessionFactory.setUsername("kermit");
    sessionFactory.setPassword("frog");
    sessionFactory.setProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("proxy.example.com", 1080)));
    return sessionFactory;
}

When the HTTP proxy requires credentials, use the FtpHttpProxySessionFactory instead. It tunnels the connections through the proxy with the CONNECT method and sends the credentials to the proxy with the basic authentication scheme. This factory supports only the passive client mode, which is its default. The following example shows its configuration:

<bean id="ftpClientFactory"
    class="org.springframework.integration.ftp.session.FtpHttpProxySessionFactory">
    <property name="host" value="ftp.example.com"/>
    <property name="username" value="kermit"/>
    <property name="password" value="frog"/>
    <property name="proxyHost" value="proxy.example.com"/>
    <property name="proxyPort" value="3128"/>
    <property name="proxyUsername" value="kermit"/>
    <property name="proxyPassword" value="frog"/>
</bean>
The FtpHttpProxySessionFactory supports only plain FTP connections. For FTPS connections through a proxy, use the proxy property of the DefaultFtpsSessionFactory.

Unlike the proxy system properties of the JVM (such as socksProxyHost), these options apply only to the sessions of the configured factory, not to all the connections of the application.