A couple of weeks ago, I received another interesting query from one of our customers. He was setting up an automated FTP download with one of his trading partners and wanted to know how he could move those files that have just been downloaded from the remote server to an archive directory on that same server. I was thinking many of you would find it useful, so I decided to share the steps I recommended then.
What we're trying to do
In order to follow this particular tutorial, you would need the following elements on your JSCAPE MFT Server:
- A JSCAPE MFT Server trading partner - Many of the sample settings you'll find on this article are based on the trading partner created in the post Setting Up A Trading Partner for Automated FTP, so I suggest you read that post first to get the right context.
- A trigger designed to perform a scheduled automatic download with a trading partner. Click that link to read a tutorial that contains all the information you need to create such a trigger.
Done reading those two posts? Let's proceed.
1. Create a trigger with the "External File Download" event type
Create a new trigger, give the new trigger a name (e.g. "Move Remote Files After FTP Download"), and then select the External File Download event type.
The External File Download event is thrown each time a file is downloaded as a result of a recently fired (download) trigger action. Examples of such trigger actions are the Trading Partner File Download and Trading Partner Regex File Download trigger actions. We talked about these two trigger actions in the article How To Set Up A Scheduled Automatic Download With A Trading Partner.
Click Next to proceed.
The next step of this automated FTP download tutorial would be to create a trigger condition that would narrow your trigger down to a specific download or specific set of downloads.
2. Specify a trigger condition that would filter out unrelated downloads
If your managed file transfer server is running in a production environment, chances are, you'll have several downloads going on at any given time. In order to make sure the trigger we're creating here only acts on a specific set of downloads, we need to put together a set of trigger conditions that would filter out all unrelated downloads.
For example, we can tell JSCAPE MFT Server to act only on those downloads that take place after 8 PM on the first day of each month. I chose this time because it jives with the schedule of the automatic download we discussed in How To Set Up A Scheduled Automatic Download... .
You can refine your filter even further by making use of other variables such as the:
- ServerIP (the IP address or hostname of the server from which the file was downloaded)
- ServerPort (the port number of the server from which the file was downloaded)
- Bytes (the number of bytes in the file)
- File (the local filename of the file that was downloaded)
- LocalPath (for the local path of the file that was downloaded)
- and many others
Once you're done, click on the Next button.
Now it's time to set up the trigger action that would move the freshly downloaded file(s) to another folder on the remote server.
3. Select the "Trading Partner Rename File" trigger action
The trigger action we'll need for moving the file(s) on the trading partner's remote server is the Trading Partner Rename File. Expand the Action drop-down list box and select that trigger action we just mentioned. Click OK when done.
4. Define the parameters for moving the files on the remote server
When the parameters dialog appears, the first setting you'll see is the Partner drop-down list box. Expand that list and select the trading partner you have downloaded files from.
Next, specify the Remote Directory that contains the source files you just downloaded (e.g. /fordownload).
After that, enter the %Name% variable into the Source File field. This variable contains the local filename of the file that was most recently downloaded, which, unless you changed it during download, will be the same as the filename in the remote server.
Lastly, specify the Destination File. This value should consist of the destination directory (on the remote server) and the filename the file should take after it's been moved. If you specify a name, then you would have "renamed" the file. Hence the name "Trading Partner Rename File". In our case, we only want to move the file, not rename it, so we just use the %Name% again.
Click the OK button when you're done.
Here's a summary of what takes place in this automated FTP download:
- A file is downloaded by another trigger (e.g. one of those files that satisfy the regex in How To Set Up A Scheduled Automatic Download...).
- The download event is captured by virtue of this trigger's External File Download trigger event.
- JSCAPE MFT Server determines whether the trigger should proceed to the trigger action part by comparing the FTP download's details with the values specified in the trigger condition. In this particular case, it asks "Did the FTP download take place after 8 pm of the 1st day of the month?". If this condition is satisfied, the trigger action executes.
- When the trigger action executes, it then moves the file from the remote directory to the destination directory.
- If multiple files satisfied the regex, then the entire process is repeated until all files have been downloaded and moved.
This concludes our tutorial. We hope to see you again next time.
Would you like to connect with us on social media? We'd love that ...