FTPSETERROR Store Server Response for Conditional Branching
<< Click to Display Table of Contents >> Navigation: Robo-FTP User's Guide > Script Programming > Script Commands > All Script Commands > FTPSETERROR Store Server Response for Conditional Branching |
Syntax: |
FTPSETERROR |
[ msg ] |
Arguments: |
[ msg ] |
Optional variable or string formatted as a server response code; if this argument is omitted the current value of %ftplastresult is used. |
Options: |
None |
|
This script command populates the %lasterror internal variable with the numeric portion of a server response. This allows you to use the IFERROR command to conditionally branch based on a server's specific response code. If the optional [ msg ] argument is omitted the %ftplastresult internal variable provides the default server response value. You may also find this command's optional msg argument handy for testing any error handling logic you may have added to your command scripts.
FTPSETERROR may also be used together with the FTPCMD command when connecting to a remote site that requires non-standard or overloaded raw protocol commands.
Each time Robo-FTP sends a command to the server, the remote site replies with a message in the following format:
[nnn] [text]
where [nnn] is a numeric value in the range of 100 to 599 and [text] is English description of the result. The following is an example of an FTP site reply:
226 Transfer complete.
Numeric values in the server reply fall into one of the following five categories:
1nn Positive Preliminary reply
2nn Positive Completion reply
3nn Positive Intermediate reply
4nn Transient Negative Completion reply
5nn Permanent Negative Completion reply
The %ftplastresult internal variable contains the most recent server reply. More information on FTP site reply codes may be found in Section 4.2 of the RFC 959 FTP specification.
Suppose you are writing a script that uploads files to a remote site with limited disk space and you want to react to the specific error 552 Disk Quota Exceeded in a different manner than all other types of upload failures. The following command script segment would branch to the "try_other_account" label if this specific reply was received from the server:
SENDFILE "Q3sales.dat"
FTPSETERROR
IFERROR= 552 GOTO try_other_account
IFERROR= $ERROR_SUCCESS GOTO upload_success
DASHBOARDMSG "File upload failed [" + %lasterror + "] " + %ftplastresult
Knowledge of server reply codes is not mandatory when writing Robo-FTP command scripts. Standard server responses are automatically recognized as either success or failure, which is sufficient for most scenarios. In rare cases where the specific type of success or failure is important to your logic, the FTPSETERROR command allows branching to handle specific response codes.
Related command(s): IFERROR, FTPCMD
See also: Using the %lasterror Variable, Using the %ftplastresult Variables, Internal Script Variables, Interactive Debugging