Introduction
The purpose of this article is to demonstrate how one can use regular expressions to create complex trigger conditions in JSCAPE Secure FTP Server. Regular expressions provide a concise means for identifying strings of interest e.g. words or pattern of characters. JSCAPE Secure FTP Server follows the regular expression rules as defined by the Java programming language, a complete guide to Java regular expressions can be found here.
Demonstration & Examples
This feature is best illustrated by providing concrete examples demonstrating what can be achieved with this feature. Starting with a timed trigger example, we will upload all text files from a specific directory starting with "John" every 15 minutes to a server location.
1) Start JSCAPE Secure FTP Server Manager.
2) Create a trigger as follows :
Select "CurrentTime" from the Event Type dropdown. Type in an appropriate name and click 'Next'. The next screen is demonstrated below :
Look at the condition specified : Minute MATCHES REGEX 0|15|30|45
What does this mean? This means that the trigger action will occur every 15 minutes. What if I wanted to execute the trigger action every half hour, for this latter requirement one would use the following regular expression : 0|30
Click on 'Next' button and setup a 'Ftps Regex File Upload' trigger action, for this to work you would have to setup Ftp Implicit or Explicit SSL service, this latter step can be done through the Server Manager. The important property of the trigger condition is the 'Regular Expression' field, fill it in with "John.*.txt" (without the quotation marks).
The expression is : John.*\.txt
This means : "John" followed by any number of any characters including the space char. Filename must end with ".txt". Therefore "John Lenon.txt" is valid, "John Abraham.txt" is valid, "John.txt" is valid but "Simon Lenon.txt" is not valid.
Apply the condition triggers so the server can begin uploading the files every 15 minutes. For verification go to the local directory where the server is installed and verify that files are uploaded, verification can also be done by looking at the server logs as it will record all files uploaded and the fact that the trigger action was executed.
For all Johns with second name starting with either with A or a B and absolutely no other letters. For this I would use the regular expression : John [AB].*\.txt
For all names ending with "Roland" I would use the following regular expression : .*\ Roland.txt
A more complex example : John [AB].*\(Lennon){1}.txt
John followed by a space character, second name starting with
either A or B, followed by any number of characters, followed by 1
"Lennon", ending with ".txt". Therefore "John Abraham Lennon.txt" is valid, "John Abraham
Lennon Lennon.txt" is also valid. Why is the second name valid? - because
there is one "Lennon" in the whole name, however "John Abraham.txt" is not valid since it does not contain a "Lennon".
As you can probably see that any regular expression which can be used in Java can be used in JSCAPE Secure FTP Server trigger / action mechanism. Where is this example useful? One common scenario could be database backups where you could set the trigger to fire every 24 hours and filter which database files to upload to a remote server location based on the regular expression used in the Ftps Regex File Upload 'Regular Expression' field. You could have multiple triggers for different name groups backing them up to a different server location, E.g. one trigger / FTPS regex upload action which could handle all files starting with A, another trigger / FTPS regex upload action which could handle all files starting with B to a different location.
The business functionality which can be constructed around these trigger / action / regular expression combo can be quite significant, consider doing this in a traditional coding application route : you would have to write significant code to handle all this, on top of that if you are adamant about using a tier architecture for coding as is the norm in large web / commercial applications it could mean a lot of work. Instead JSCAPE Secure FTP Server can really come in handy here for these data handling jobs. Once the triggers / actions are setup the user can just leave it running and it continue to perform it's work, meaning there is little work for the server administrator in such a scenario.
It should come as no surprise that regular expressions can be used in other scenarios such as File Downloads / File Uploads. For example the following screen shows how a multiple condition for File Uploads can be setup in JSCAPE Secure FTP Server :
We can see here that there are two conditions :
1) The file must be successfully uploaded.
2) The file name must satisfy the regular expression : John [AB].+\(Lennon){1}.txt
The regular expression has the following meaning :
John followed by a space character, followed by either A or B, followed by atleast one other character,
followed by one "Lennon" word group, followed by ".txt". E.g. John ArLennon.txt is valid according to this expression but John ALennon.txt is not valid since there are no characters after "A".
A similar setup can also be done for File Download scenarios :
We can see here that there is the condition :
*) The file name must satisfy the regular expression : [ABC].*\
The regular expression has the following meaning :
The username must begin with A, B or C followed by any number of any characters.
Where can one use this? If the business functionality requires that a confirmation of the download is sent to the user once he / she downloads a file this trigger can be used together with a "Send Email" action to send a confirmation of the download to the user which has a username satisfying the regular expression. Thus a email will be sent to the user with a username of "Abacus" but it will not be sent to a user with a username of "Zeus".
Another scenario where this process can be useful is the "Directory
Monitor File Changed" where the action which could possibly be a File
Regex Upload can filter files by a providing regular expression. Directory Monitor File Changed trigger is fired when a file in a monitored directory is changed.
Thus we can see that the business functionality that can be constructed is virtually limitless, a knowledge of Java regular expressions is perhaps the only limiting factor here. The link provided in the "Introduction" should help in this regard. Also note that JSCAPE Secure FTP Server has a built in "Test Expression" feature which allows you to confirm whether the expression is correct or not, this on the fly feature can make life very easy and greatly help in expediting the process of setting up this functionality.