FTP Adapters

Remote files are usually fetched by employing the File Transfer Protocol (FTP), while local files are transferred onto a remote server using the same FTP. These two tasks are supported by the framework using inbound and outbound channel adapters.

The inbound channel adapters connect to an FTP Server to fetch the remote files and pass them as messages with the current file (Message<File>) as payload. The outbound channel adapters act in the opposite direction: they connect to channels, consume the messages, and write them to remote server directories.

Both adapters, represented by inbound-channel-adapter and outbound-channel-adapter, are included in the ftp namespace support. Before setting up the adapters, one critical piece of information is required by the adapters: connection (or session) details.

Session Factory

The adapters should know the server details to connect to, including the username and password. Framework’s DefaultFtpSessionConnectionFactory class provides these details. You should declare this bean in your config file with the appropriate properties set. The bean reference is then provided to the adapters as a session-factory attribute.

First, let’s see how we can set up a session factory. In your XML file, declare the factory class and provide the necessary details:

<bean name="sessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory"> <property name="host" value="ftp.madhusudhan.com"/> <property name="username" value="jsi"/> ...

Get Just Spring Integration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.