Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.
decrypt_uploaded_files.s
Robo-FTP Server can automatically decrypt PGP files as they are uploaded by an FTP, FTPS, SFTP or HTTP(S) client.
This sample script was written for use with Robo-FTP Server v3.3. The steps may vary slightly for newer or older versions. This sample script is NOT for use with the Robo-FTP client.
Robo-FTP Server provides a powerful event-driven automation interface which enables you to launch Robo-FTP scripts in response to events such as a user logging on, uploading a file, etc. This interface is called Server Event Scripts.
Several built-in variables are automatically populated whenever a Server Event Script is triggered. These variables contain information relevant to the event. For example, when a user uploads a file, variables are populated with information like the filename, the path to the file, etc. This page in the Help file describes the events and built-in variables available: Programming Server Event Scripts.
The sample script below is designed to be triggered by the Upload Complete event. When executed by Robo-FTP Server, it attempts to decrypt the uploaded file. If successful, the resulting decrypted file is moved into a folder named Decrypted
and the original encrypted source file is deleted. If decryption fails the uploaded file is moved to a Rejected
folder.
To load your PGP keys into Robo-FTP Server:
- Launch the Robo-FTP Server Configurator program by clicking Start → All Programs → Robo-FTP Server → Script Settings
- Switch to the Configure PGP menu.
- Import your private PGP key for decryption. If you don't yet have a key you can create one on this menu.
- If you also need to verify the PGP signature of uploaded files then import the senders' public keys as well.
- Click OK to close the Configurator.
To prepare the server event script file and destination folders:
- Download this sample script and save it as
decrypt_uploaded_file.s
(use link above) - Move the script to the
ProgramData\Scripts
directory under your Robo-FTP Server installation folder - Double-click the file to edit the script. Modify the /pw=x option on the PGPDECRYPT row to match the passphrase on your PGP key. Save the changes.
- Create the
c:\Uploads\Decrypted
andc:\Uploads\Rejected
folders on your computer. - Modify the Windows security permissions on each folder to grant the Network Service account permission to read, write, modify, and list files in the folder. Do this by right-clicking the folder and selecting Properties from the pop-up context menu and then switching to the Security tab on the Properties window. Note: If you previously changed the Robo-FTP Server service to run as another account you'll need to give that other account permission instead of Network Service.
To configure Robo-FTP Server to launch the event script at the appropriate time, follow these steps:
- Launch the Robo-FTP Server Console program by clicking Start → All Programs → Robo-FTP Server → Server Console
- Select Automation in the navigation bar on the left
- Select "Enable for all" under Server Event Scripts on the right
- Select "Upload Complete" from the Server Event drop-down list
- In the Event Script File Name box enter the full path to the
decrypt_uploaded_file.s
script file that you saved earlier - Click the Apply button
Once all these steps are complete, upload a file encrypted with your public PGP key to Robo-FTP server and then check the Decrypted
folder to verify success. Next upload a file encrypted with some other key (or not encrypted at all) and verify that Robo-FTP Server moves it to the Rejected
folder. The script execution results are logged to the ProgramData\Scripts
directory.
Hint: You can use the Robo-FTP client program for testing. Here is an sample showing how: Encrypt and upload a file to an FTP server with error handling.
1 * Set folder paths
2 SET put_decrypted_files_here = "c:\Uploads\Decrypted\"
3 SET put_rejected_files_here = "c:\Uploads\Rejected\"
4
5 * Enable Logging
6 LOG "upload_event_script.log"
7
8 * Detect failed upload
9 IFNUM!= %event_uploadresult 0 GOTO move_rejects
10
11 * Attempt PGP decryption ...
12 PGPDECRYPT %event_uploadfile put_decrypted_files_here /pw="Secret" /signature=ignore
13 IFERROR GOTO move_rejects
14
15 * If we got to this line that means automatic PGP decryption worked
16 * so we can get rid of the encrypted source file.
17 DELETE %event_uploadfile
18 RETURN %lasterror
19
20 :move_rejects
21 MOVE %event_uploadfile put_rejected_files_here