Getting started with the FTP Connector for MuleSoft

Requirements: /n software Connectors for MuleSoft

Introduction

The /n software Connectors for MuleSoft include pure java Connectors and Modules designed to seamlessly integrate with MuleSoft. The /n software Connectors for MuleSoft extend the functionality of MuleSoft and provide robust enterprise ready enterprise ready Internet connectivity, secure messaging, and file transfer.

This guide will focus on the basics of the FTP Connector, which is used to communicate with FTP servers. The FTP Connector supports FTPS (FTP over SSL). For details on installation and other connectors please see the Online Documentation.

Contents

FTP Receive Module

The FTP Receive module will connect to a server and download the specified file(s). It acts as a source module and will bring files into your flow. The below properties are necessary to connect and download files.

Core Properties

PropertyDescription
FTP ServerThe remote FTP host address
FTP PortThe port on which to connect
UserThe User credential for performing FTP logon
PasswordThe Password for the specified User
Remote PathThe path on the FTP host from which files should be downloaded
File MaskAn optional mask for the files at the Remote Path

SSL Properties

For secure FTP transfer, SSL properties should also be set. The SSL Start Mode property determines whether and how the connector will attempt to negotiate SSL with the remote host. If set to None, the connection will be made over plaintext (no encryption). If set to Implicit, the SSL negotiation will begin immediately after establishing a connection to the server. If set to Explicit, SSL negotiation will occur after connecting to the server and asking for an SSL-secured session via the AUTH TLS command. If set to Automatic, SSL will be negotiated implicitly when connecting to the expected SSL FTP port (990) and explicitly otherwise.

The SSL Server Cert property consists of a collection of fields that determine whether the connector should trust the SSL certificate presented by the server (this property may need to be set to Edit inline for the collection of fields to appear). The simplest approach is to set SSL Accept Server Cert Accept Any to True, which causes the connector to accept any SSL certificate presented by the specified FTP Server. For more control, the specific certificate expected from the server can be set via the combination of SSL Accept Server Cert Store Type, SSL Accept Server Cert Store, SSL Accept Server Cert Store Password, and SSL Accept Server Cert Subject.

Similarly, the SSL Cert property consists of a collection of fields that determine the client SSL certificate; this is only necessary if client authentication is required for the specified FTP Server. The certificate is set via the combination of SSL Cert Store Type, SSL Cert Store, SSL Cert Store Password, and SSL Cert Subject.

FTP Receive Usage

Dragging an instance of the FTP Receive module into a Mule project will automatically establish a source module in your flow. A generic source module is one which produces mule events for processing. FTP Receive is a source module which produces one mule event per file downloaded. A configuration must be applied to the connector, including the core properties mentioned in the previous section. Additionally the polling settings should be configured in the general connector settings pane.

The connector will poll the specified FTP Server at the specified Remote Path for any files matching the File Mask. Any files found will be sent through the MuleSoft message pipeline. The Delete Mode property can be set if files should be deleted after downloading.

After download, the files enter the Mule message flow. After the FTP Receiver passes the file data off to another component within the Mule flow, certain attributes of the file are available. In Mule 3.X, these message context attributes are accessed by referencing the inboundProperties of the message e.g. message.inboundProperties.ReceivedFileName. In Mule 4.X, these properties are available through the attributes keyword, e.g. attributes.ReceivedFileName.

Here is an example of a simple flow that receives files from an FTP Server and writes them to the local drive:

An example FTP Receive flow and configuration

FTP Send Module

The FTP Send module will establish a connection to a FTP server and upload the specified file(s). The below properties are necessary to connect and upload files.

Core Properties

PropertyDescription
FTP ServerThe remote FTP host address
FTP PortThe port on which to connect
UserThe User credential for performing FTP logon
PasswordThe Password for the specified User
Remote PathThe path on the FTP host where the files should be uploaded
Remote FileThe name of the file once uploaded to the remote host

SSL Properties

For secure FTP transfer, SSL properties should also be set. The SSL Start Mode property determines whether and how the connector will attempt to negotiate SSL with the remote host. If set to None, the connection will be made over plaintext (no encryption). If set to Implicit, the SSL negotiation will begin immediately after establishing a connection to the server. If set to Explicit, SSL negotiation will occur after connecting to the server and asking for an SSL-secured session via the AUTH TLS command. If set to Automatic, SSL will be negotiated implicitly when connecting to the expected SSL FTP port (990) and explicitly otherwise.

The SSL Server Cert property consists of a collection of fields that determine whether the connector should trust the SSL certificate presented by the server (this property may need to be set to Edit inline for the collection of fields to appear). The simplest approach is to set SSL Accept Server Cert Accept Any to True, which causes the connector to accept any SSL certificate presented by the specified FTP Server. For more granular control, the specific certificate expected from the server can be set via the combination of SSL Accept Server Cert Store Type, SSL Accept Server Cert Store, SSL Accept Server Cert Store Password, and SSL Accept Server Cert Subject.

Similarly, the SSL Cert property consists of a collection of fields that determine the client SSL certificate; this is only necessary if client authentication is required for the specified FTP Server. The certificate is set via the combination of SSL Cert Store Type, SSL Cert Store, SSL Cert Store Password, and SSL Cert Subject.

FTP Send Usage

Dragging an instance of the FTP Send module into a Mule project will automatically establish an FTP operation module in your flow. A generic operation module receives a mule event from a source module (with possible intermediary steps) and processes it. The FTP Send module is an operation module which "processes" data by uploading it to remote FTP hosts. A configuration must be applied to the connector, including the core properties mentioned in the previous section.

Whenever a Mule message is provided to the connector during the MuleSoft flow, the connector will connect to the specified FTP Server and upload the data at the location given by Remote Path and Remote File. The Overwrite property can be set if files should be uploaded even if a file of the same name already exists on the server.

If files should retain their original name after upload, this can be done by using the message context properties in the Remote File property. In Mule 3.X this should be set to #[message.inboundProperties.ReceivedFileName]. In Mule 4.X, the corresponding syntax is #[attributes.ReceivedFileName].

Below is an example of a simple flow that receives files from an FTP Server and then uploads them to a different location on the FTP Server. You can imagine that the files are processed during the MuleSoft flow (not shown) and then uploaded back to an archive location.

An example FTP Sender flow and configuration

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.