Script Library

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.


ftp_monitor.s

Download

This sample script monitors a remote FTP server and sends an email notification when changes are detected. The script is a loop that runs every 5 minutes so it could be installed as a Windows Service. On the very first execution, every file in the remote folder is reported as a "new." On subsequent runs, the script detects and reports what has changed since the last run. The script is able to detect new files, deleted files, and modified files.

This script could be easily modified to change its behavior. For example you could connect to an SFTP site, change the looping frequency, include subfolders, ignore files ending with the ".tmp" file extension, suppress the initial email report where all files are listed as "new" files, download or archive changed files, or insert information about the changes into a database using Robo-FTP's built-in database commands. There are literally too many possible permutations and combinations to list.


  1  :loop
  2  FTPLOGON "MySite"
  3  FTPCD "directory/to/monitor"  
  4  FTPDIFF "*" /append 
  5  IFERROR GOTO interrupt
  6  IFNUM= %ftpdifffiles 0 GOTO pause
  7  SET incomplete = ""
  8  :diff_loop
  9  FTPGETDIFF /commitlast 
 10  IFERROR= $ERROR_READ_EOF GOTO done
 11  IFERROR GOTO interrupt
 12  SET email_line = %ftpdifffilepath + " " + %ftpdifffiletext + "\n"
 13  SET email_body = email_body + email_line
 14  GOTO diff_loop
 15  :interrupt
 16  SET incomplete = "\n\nProcessing halted early. [" + %lasterror + "]  "
 17  :done
 18  SET email_subject = "Changes detected at " + %datetime
 19  SET email_body = subject + "\n\n" + email_body + incomplete
 20  EMAIL email_body /subject=email_subject
 21  SET email_body = ""
 22  :pause
 23  PAUSE /for=300
 24  GOTO loop

Browse complete list of scripts