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.
NOTE: The technique demonstrated in this script is not needed for file transfer or email commands. Robo-FTP 3.10 and later have built-in features for automatically retrying failed connections in those cases. Use the "Retry Count" and "Retry Delay" settings in the Site Manager in the Configurator to configure this (see the Help file for details).
Error-handling generally falls into to two categories:
- Unrecoverable errors, where you typically want to abort the process and notify somebody
- Recoverable errors, where you want to simply re-try the failed attempt until it works.
Things get a little trickier when you encounter what should be a recoverable error, but under certain circumstances does not recover. If you are not careful, you can end up with an infinite loop.
One way to avoid this is to use LOOPCOUNT and related commands to limit the number of times you retry something.
The following script attempts to connect to an FTP site 10 times, pausing for one minute between attempts. If it can't connect after 10 tries, it aborts and sends an email notification.
1 loopcount 10 2 :connect_loop 3 ftplogon "mysite" 4 iferror= $error_success goto connected 5 pause /for=60 6 loopto connect_loop 7 ;; Connection attempts failed 10 times 8 CREATEMAIL "Script Notifier" "firstname.lastname@example.org" "Connection failed" "FTP server appears to be down" "" 9 sendmail "smtp.mycompany.com" "Sys Admin" "email@example.com" 10 EXIT 11 12 :connected 13 ;; Connection worked -- continue script