Skip to main content
All CollectionsIntegration DevelopmentAdvanced Development - File transfers over the network
Introduction to How to use SFTP and FTP/FTPS Tasks in your Processes
Introduction to How to use SFTP and FTP/FTPS Tasks in your Processes

Examples of use file transfer protocols in Frends Processes

R
Written by Riku Virtanen
Updated over 8 months ago

How to use SFTP and FTP/S Tasks in your Processes

In order to use these Tasks in your Processes you first need to import them to your Frends. The Tasks are all included in their own packages Frends.SFTP and Frends.FTP, but they need to be imported separately. This can be done easily from the Task View by searching for packages. For FTP Tasks you need to search Frends.FTP and import the Tasks listed in there.

Now that we have successfully imported the Tasks, we can go through a few use cases for how to use them in your Processes.

Best practices

SFTP and FTP transfers are usually repeatable operations. As a result of this it's recommended to create Subprocesses to transfer files via an SFTP or FTP connection.

All file transfers may have some connection issues that are not taken into consideration in the Task itself. You can tackle these issues by enabling the Retry on failure option in the Task's advanced settings. It's recommended to use this so that the Task can retry the execution if any errors are thrown from the Task. Note that in order for this to work the Throw error on fail option needs to be enabled in the Task's options tab.

Simple transfer

The most basic use case for transferring files via an SFTP connection is done with the DownloadFiles and UploadFiles Tasks. The implementation is recommended to be done in a Subprocess because the transfer can then be duplicated to multiple situations.

First, we need to set the Trigger parameters which are given by the main Process. These parameters can then be used in the SFTP Task. Note that you will need to set all required attributes as Trigger parameters which will then be used with the SFTP Task. Usually, you will need at least the server address, port number if multiple different ports are used and credentials for authentication. Also, you need to give source and destination information of the file/files to be transferred. With these Trigger parameters set we can use them in the SFTP Task by referencing them with the reference #trigger.data.ParameterName. You can then configure the Task for how you want the transfer to be conducted.

The Task can be configured by following the previous modules. As the file transfer Tasks are prone to errors, for example connection errors, it is recommended to use error handling with the Tasks.

Transferring a file from one SFTP server to another

Sometimes there is a need to transfer files from one SFTP server to another. Similar to the first use case, this is also recommended to do in a Subprocesses, so you need to configure the Trigger's parameters to take every required value and pass them to the Tasks. It is recommended to use a Scope Element to wrap the SFTP Tasks so that any errors occurring in the Tasks can be caught by the same Catch Element and handled in the error handler. This way we can use the Subprocesses in our main Process and handle the file transfer without needing to create a new one.

SFTP Tasks in Conditional Trigger

One great use case for SFTP.ListFiles Task is to use it in a Conditional Trigger. At the moment Frends already has a File Trigger which can be used in polling specific local directory or network drives but when you have a need to poll a directory in SFTP server, things turn little bit different. Fortunately SFTP.ListFiles come to the rescue. In order to use the Task as a Conditional Trigger we have to first create a Subprocess which will handle the polling feature. Just remember to make the Subprocess as generic as you can so it can be used with multiple Processes and with different servers. The actual Subprocess can be pretty simple. The only thing you need is the SFTP.ListFiles Task and a whole bunch of parameters for your Manual Trigger. Here is an example of this use case:

The parameters you are going to need for the Subprocess are source directory, file mask, destination directory, server address, username and password. In some cases other parameter can also be used when there's a need to specify some other options for the Task. In these case you can just modify the already made Subprocess and add the Trigger references (#trigger.data.ParameterName) to the Task's parameters.

Multi Functional Transfer Subprocess

When you have a need to make multiple different transfers with your Processes it sometimes more useful to create a multi functional transfer Subprocess which will handle the transfer features whether the Transfer is via SFTP or FTP servers.

In order to make this happen you need to have all the possible settings set for the manual Trigger. In this case you would need to take into consideration the fact that is the transfer suppose to be done from SFTP or FTP server, is the destination SFTP or FTP server or local file share and all the operations and actions needed for those tasks.

The Process starts as usual with a manual Trigger with all the necessary parameters. The the first step is to make a new object with all possible values for the Tasks' parameters. Then the transfer will go through every path and the Process will determine with the help of Decision Elements what kind of transfer is to be conducted.

Note that in this example both of the DownloadFiles Tasks needs to have destination directory as a some directory on Agent's local file share where the files will be moved or copied from if the destination is a file share.

The next article is Introduction to Handlebars

Did this answer your question?