Sample: Unzip Uploaded Files

Top  Previous  Next

 

The sample script below is designed to be triggered by the Upload Complete event. When executed by Robo-FTP Server, it moves uploaded zip files to a pre-defined directory, unzips the contents and deletes them. The script automatically quarantines invalid or password protected zip files along with any other files not named with the .zip extension.

 

LOG "upload_event_script.log"

TRACELOG "upload_event_trace.log"

MOVE %event_uploadpath "c:\temp"

SET zip_path = "c:\temp\" + %event_uploadfile

SETRIGHT extension = %event_uploadfile 4

IFNSTRCMPI extension ".zip" GOTO invalid_file

UNZIP zip_path "c:\destination" "*"

IFERROR GOTO invalid_file

DELETE zip_path

GOTO done

:invalid_file

;; Not a valid zip file

MOVE zip_path "c:\quarantine"

:done

DISPLAY

 

 

To configure Robo-FTP Server to launch this event script for all uploads:

 

1. Copy the the script above and save it as a new file named unzip_uploaded_file.s
2. Launch the Robo-FTP Server Console program.
3. Select Automation in the navigation bar on the left.
4. Select "Enable for all" under Server Event Scripts on the right.
5. Select "Upload Complete" from the Server Event drop-down list.
6. In the Event Script File Name box enter the full path to the unzip_uploaded_file.s script file that you saved earlier.
7. Click the Apply button
8. Select Administration in the navigation bar on the left
9. Write down the name of the account displayed in the Login box. The Login box will be disabled if the service is running but you should still be able to read the account name. Network Service is the name of the default account used by Robo-FTP Server.
10. Create these folders if they do not already exist on your computer: c:\temp, c:\destination and c:\quarantine
11. Right click on each folder listed in the previous step and select Properties from the pop-up context menu. Modify the security permissions on each folder to grant Robo-FTP Server's login account permission to read, write, modify, and list files in the folder.

 

Once all these steps are complete, upload a zip file to Robo-FTP server and then check the c:\destination folder for the unzipped contents. Then upload a non-zip file and verify that Robo-FTP Server moves it to the c:\quarantine folder.

 

 

See also: Programming Server Event Scripts