Here at Advanced Cyber Solutions, we like to share great discoveries and solutions on the basis that it might help others in pursuit of the same outcomes. So when we were challenged, this week, by a customer to help them with automated file transfers using conditional logic. We not only gleefully accepted but we also thought we would share the results!
A large and well-known logistics company asked us to help with a particular case, whereby they would receive hundreds of files throughout the day. These files would need to be sorted through and sent to a number of possible locations based on the contents an XML tag contained in the file.
Sounds easy enough, logically speaking. But how could we fully automate this process?
The Automated File Transfer Source and Destinations
As with any such automated file transfer project, we would recommend Ipswitch's MOVEit Automation. A tool which can both move files between various file repository types and apply some form of scripting in the process.
Initially we wanted to create a pilot, using local Windows Explorer folders. So we created an input folder named "In" and two output folders under the names of "Southampton" and "Cannock".
XML files would be collected from the "In" folder. Conditional logic would be applied to read the XML tag content and deliver the file to either the "Southampton" or "Cannock" folder. Depending on the presence of either "TPEN" for Southampton or "TBOW" for Cannock, respectively.
Ipswitch MOVEit Cloud meets all of the NCSCs cloud security principles - Want to learn more?Read our blog here.
Scripting the Conditional Logic
Next, we needed to create a script which could inspect the XML tag content for those two terms.
To do this, we used the PowerShell capabilities of MOVEit Automation to produce the following.
If you are not familiar with PowerShell, fear not. I will dissect!
This script opens the XML file picked up from the source, reads the content and looks for an XML tag called "RecieverCode". It then compares the content of that tag to "TPEN" or "TBOW", assigning a variable named "RCode" with a 0 or 1.
A result of 0 means the file should be moved to the "Southampton" folder; and a result of 1 should see the file being delivered to the "Cannock" folder.
Hanging it all Together with MOVEit Automation
With our folder structure in place; and our script created. We now need to create the workflow in MOVEIt Automation.
Starting with the source, we configured the task to collect XML files from the "In" folder.
We then created a FOR LOOP, so that each file collected can be parsed through the script, which has been named "XML Receiver Code Logic".
Once the script has run, we then use IF statements to test the "RCode" variable for the presence of a 0 or 1, allowing us to determine the destination folder.
The result is that two sample files were routed to the correct local folders.
Subsequent to demonstrating the theory. We were able to replace the source and destination folders with live SFTP servers; and sort through hundreds of files, without even breaking a sweat.