Passing External Values Into Command Scripts
<< Click to Display Table of Contents >> Navigation: Robo-FTP User's Guide > Script Programming > Select Topics in Script Programming > Passing External Values Into Command Scripts |
It is possible to pass up to nine values into a Robo-FTP script via command line arguments. The -p command line switch is combined with a single digit between 1 and 9 and then followed by a value. For example:
robo-ftp.exe -p1 FridaySales.xls
Values passed in on the command line are available for use in script logic via nine internally defined variables named %1 through %9. The numeral in the variable name corresponds to the digit that follows the -p switch. The example below would assign the value FridaySales.xls to the script variable named %1. This variable could be used in the script as follows:
SENDFILE %1
Now consider the following command line.
robo-ftp.exe -p1 "ACME Bricks" -p2 "SENDFILE 'newdata.dat'"
Given the command line above, the following script file:
DASHBOARDMSG "Connecting"
FTPLOGON %1
PERFORM %2
DASHBOARDMSG "Done"
FTPLOGOFF
EXIT
... would be executed as if it was originally written as:
DASHBOARDMSG "Connecting"
FTPLOGON "ACME Bricks"
SENDFILE 'newdata.dat'
DASHBOARDMSG "Done"
FTPLOGOFF
EXIT
Notice above that values with embedded spaces must be enclosed in quotation marks. When you need to pass in a value that itself contains quotations marks you can combine pairs of single and double quote characters.
The advantage to the -p switch syntax over the legacy method (see below) is that Windows environment variables (e.g., %SystemDrive%, %USERNAME%, etc.) as well as user defined strings may be passed into Robo-FTP. You cannot mix multiple environment variables and/or environment variables and user strings in the same argument. Use of this method and the legacy method on the same command line is not recommended.
Handling Missing Parameters
A script that depends on external parameter values should be designed to fail gracefully when they are unexpectedly absent. One way of handling the situation is by assigning the expected variable value to a test variable and trapping the error condition that would occur if the variable is missing, for example:
SET testvar = %1 ;; error if %1 is missing
IFERROR= $ERROR_VAR_NOT_FOUND GOTO handle_missing_arguments
It is possible to create scripts with optional external parameters by assigning the expected variable value to a local script variable that has already been assigned a default value. With this technique, the default value makes it possible to simply ignore the $ERROR_VAR_NOT_FOUND error returned when attempting to assign the missing variable, for example:
SET ArchivePath = "c:\archive\" + %date ;; assign default value
SET ArchivePath = %2 ;; error if %2 is missing
WORKINGDIR ArchivePath ;; uses default if %2 is missing
Legacy Method
It is also possible to pass values into Robo-FTP by using either the & or % character as a string delimiters, for example:
&argument&
%different argument%
The first argument, reading left to right, is assigned to a variable named %1, the second argument is assigned to %2, and so on.
Related command(s): EXEC, CALL, CHAIN
See also: Script File Variables, Launching Robo-FTP with Command Line Switches