11. FTP/FTPS Adapters

11.1 Introduction

File Transfer Protocol (FTP) is a simple network protocol which allows you to transfer files between two computers on the Internet.

There are two actors when it comes to FTP communication - client and server.
To transfer files with FTP/FTPS, you use client which initiates a connection to a remote computer
running an FTP server software. After the connection is established, the client can choose
to send and/or receive copies of files.

Spring Integration supports sending and receiving files over FTP/FTPS by providing two types of clients -
Inbound Channel Adapters and Outbound Channel Adapters as well as convenient
namespace configuration to define these clients.

11.2 FTP Inbound Channel Adapter

FTP Inbound Channel Adapter is a special listener that will connect to the FTP server and will listen
for the remote directory events (e.g., new file created) at which point it will initiate a file transfer.

As you can see form the configuration above you can configure FTP Inbound Channel Adapter via inbound-channel-adapter
element while also providing values for various attributes such as username and password to connect to an FTP server,
as well as other attributes. Please refer to the schema for more details on these attributes.

It is also important to understand that FTP Inbound Channel Adapter is a polling consumer and
therefore you must configure a poller (global or local).
Once the file has been transferred a Message with java.io.File being a payload will be generated and sent to the channel
identified with channel attribute.

11.3 FTPS Inbound Channel Adapter

FTPS Inbound Channel Adapter adds support for secured file receive operations with
FTP servers that support Transport Layer Security (TLS). Configuration of the adapter itself is very similar to the
FTP Inbound Channel Adapter and is use the same inbound-channel-adapter element but from the FTPS namespace.

11.4 FTP Outbound Channel Adapter

FTP Outbound Channel Adapter is a special MessageHandler that will connect to the
FTP server and will initiate an FTP transfer for every file it will receive in the payload of the Message. It also supports several
representation of the File so you are not limited only to the File object. FTP Outbound Channel Adapter
supports the following payloads: 1) java.io.File - the actual file object;
2) byte[] - byte array that represents the file contents; 3) java.lang.String -
represents the file path.

As you can see form the configuration above you can configure FTP Outbound Channel Adapter via
outbound-channel-adapter element while also providing values for various attributes such as username
and password to connect to an FTP server, as well as other attributes. Please refer to the schema for
more details on these attributes.

11.5 FTPS Outbound Channel Adapter

FTPS Outbound Channel Adapter adds support for secured file send operations with FTP servers that support
Transport Layer Security (TLS). Configuration of the adapter itself is very similar to the
FTP Outbound Channel Adapter and is use the same outbound-channel-adapter element but
from the FTPS namespace:

Note

A more practical way to configure these types of adapters would be via Spring's property
placeholder (http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-placeholderconfigurer)