Simple Error Trapping

Top  Previous  Next

 

There are several possible points of failure when using the FTP protocol to upload a file over a dial-up connection.  The example below illustrates judicious use of the IFERROR command to change the script's behavior depending on how and when an error occurs:

 

DIALNET "Internet Connection" /user="myname" /pw="mypassword"

;; check for dialup connection timeout

IFERROR= $ERROR_CONNECT_TIMEOUT GOTO connect_timeout

;; just exit without displaying message if any other dialup error

IFERROR!= $ERROR_SUCCESS GOTO exit

;; connect to remote site but disconnect modem without message if logon fails

FTPLOGON "ftp.acme-widget.com" /user="anonymous" /pw="any" /timeout=30

IFERROR!= $ERROR_SUCCESS GOTO disconnect

;; change to desired subdirectory on remote site

FTPCMD "CWD robo-ftp/incoming"

IFERROR GOTO subfolder_unreachable

;; upload a file

SENDFILE "datafile" /timeout=60

;; check for send time-out

IFERROR= $ERROR_OPTIMEDOUT GOTO xmt_timeout

IFERROR GOTO send_failed

LOGMSG "Upload Success!"

;; logoff and disconnect

:logoff

FTPLOGOFF

:disconnect

DISCONNECT

:exit

STOP

:connect_timeout

MESSAGEBOX "**ATTENTION: Cannot connect, dialup failure"

STOP

:subfolder_unreachable

MESSAGEBOX "**ATTENTION: Unable to change remote subdirectory"

GOTO logoff

:xmt_timeout

MESSAGEBOX "**ATTENTION: Upload timeout"

GOTO logoff

:send_failed

MESSAGEBOX "**ATTENTION: Upload failed"

GOTO logoff

 

 

Related command(s): IFERROR, LOOPIF, GOTO

See also: Script File Result Codes, %lasterror, Interactive Debugging, List of Sample Script Files, Script File Wizard, Script Programming, Script Commands