Monitoring A Remote SFTP Server for Newly Added Files

Directory monitors can be used to monitor a directory for new files. Learn how you can use this to monitor a remote SFTP server online at JSCAPE!
  1. Blog

Most users of JSCAPE MFT Server are already familiar with directory monitors. You often use it to monitor a directory for newly added files. Although that capability has helped immensely in automating a lot of business processes, it had its limitations. In the past, directory monitors could only be used to monitor local directories and UNC paths but not directories on remote servers. In the upcoming MFT Server 11, that's going to be possible.

Brief review of directory monitors

For the uninitiated, the directory monitor module is one of the most widely used automation-enabling features of JSCAPE MFT Server. Usually combined with triggers, directory monitors often act as "initiators" of automated processes. They monitor a directory for certain events (a newly added file, a file deletion, a file change, and so on) which then sets off a trigger that in turns carries out an automated task, e.g. transfer a file to a remote server, move a file to a folder for archiving, send out an email notification, and so on.

For more information about directory monitors, you may read the online documentation or watch this video:

Monitoring directories on remote servers

As mentioned earlier, previous versions of MFT Server could only monitor local directories and UNC paths. But starting version 11, directory monitors could already be used to monitor directories on remote servers. More specifically, MFT Server 11 will be able to monitor the following types of remote services:

  • AFTP
  • WebDAV
  • Amazon S3
  • SFTP
  • SMB
  • FTP
  • FTPS Implicit
  • FTPS Explicit

One particular use case is to monitor a directory on a remote SFTP server for newly added files. Once a file arrives at the monitored directory, MFT Server could then automatically download that file(s) for local processing.

directory_monitor_sftp_server

How to monitor a remote SFTP server for newly added files

Let me now show you how to implement that.

Prefer to watch a video version of this tutorial instead? Play the video below. Otherwise, skip it.

1. Make sure you have an existing SFTP trading partner

To monitor a directory on a remote SFTP server, that server should be associated with a MFT Server Trading Partner object.

sftp trading partner

As we already have several online resources about trading partner, we invite you to review those if you don't know what trading partners are yet. Here are some links to get you started:

Once you have your trading partner ready, the next step would be to create a directory monitor to monitor you SFTP trading partner.

2. Create a directory monitor to monitor your SFTP trading partner

Go to the Directory Monitors module and click the Add button to add a new directory monitor.

directory monitor for sftp server

Give the directory monitor a Name and select the trading partner in Step 1 from the Use trading partner drop-down list.

In the Directory field, you may specify the specific relative path of the directory you want to monitor. So, for example, you may enter something like /folder1/subfolder1 if that's the folder you want to monitor. I just entered '/' because I simply want to monitor the root folder of the user account associated with my trading partner.

As usual, you may also configure other settings like the Monitor interval, Latency period, and so on. Lastly, because I want to monitor this remote directory for newly added files, I make sure the Monitor file add setting is checked.

Click OK to proceed.

directory monitor for sftp server parameters

You should then see your newly created directory monitor on the screen.

newly created directory monitor

We now proceed to create the trigger that would download files from your SFTP trading partner.

2. Create a trigger to download files from your SFTP trading partner

Go to the Triggers module and then click the button.

add trigger for downloading from sftp server

Give the trigger a Name and then select the Directory Monitor File Added event type from the drop-down list. This will tell the trigger to listen to any file additions to any monitored directory.

directory monitor file added event type

Because we want this trigger to respond only to those directory monitor file added events that originate from the 'Dirmon for TP1-SFTP' directory monitor (which is the directory monitor that monitors our remote SFTP server), we specify that in the trigger conditions box like so:

MonitorName = "Dirmon for TP1-SFTP"

You may replace the text enclosed by the quotation marks with the name of your directory monitor.

Click Next to proceed.

trigger condition for directory monitor

It's now time to add the trigger action that would download the files from the SFTP server. Click the Add button.

add trigger action

And then select the Trading Partner File Download trigger action. Click OK.

trading partner download file trigger action sftp

After that, you'll need to set the trigger action parameters.

First, select the trading partner from the Partner drop-down list.

Next, enter the %File% variable into the Remote File field. This variable contains the complete path of the file that was added into the directory of the remote SFTP server we are monitoring.

Lastly, we specify the local file into which this downloaded file will be stored. Because we just want to retain the file's original filename, we specify the Local File value like so:

C:\Downloads from TP1-SFTP\%Name%

Of course, you would have to replace C:\Downloads from TP1-SFTP\ with your own local directory.

sftp trading partner download file trigger action parameters

That's it. Now you know how to configure MFT Server to monitor a remote SFTP server for newly added files.