Variables

Top  Previous  Next

 

Variables may be used to pass values to script command arguments and options. Variables may be assigned string values up to a maximum length of 4096 characters (see Command Syntax.) No more than 4096 variables may be defined at one time. Once a variable is created it remains defined until it is unassigned with the SET command or Robo-FTP terminates. All variables have global scope except user-defined FUNCTION arguments that are not otherwise created or assigned elsewhere in a script. Variable names are not case-sensitive. For example, abc and ABC are the same variable.

 

Internal variables are automatically created and assigned values by the Robo-FTP script processor. You should familiarize yourself with the list of internal variables because they can make certain script development tasks much easier. The names of internally defined variables begin with a percent "%" character.

 

User-defined script variables are created and assigned values by script commands like SET and SETNUM. The names of user-defined variables should begin with at least one alphabetic character and may be up to 255 characters in length. Creating a user-defined variable with a name that begins with a percent or dollar sign character is possible but unwise because it invites confusion with the built-in internal variables.

 

The following example shows a user-defined variable named address being created by the SET command and then passed as an argument to the FTPLOGON command.

 

SET address = "www.robo-ftp.com"

FTPLOGON address /user=anonymous

 

If you need a variable with a value that contains double quotation marks, enclose that value in single quotes:

 

SET password = '"secret"' ;; value of password is "secret"

 

Conversely, if you need to use a value that contains single quotes, enclose that value in double quotes:

 

SET password = "'secret'" ;; value of password is 'secret'

 

Robo-FTP script files may perform string manipulation on variables. For example, the SETLEFT, SETRIGHT, and SETMID commands allow extraction of substrings from the left to right, right to left, and from the middle of a string. The following example copies the two leftmost characters of the value of the %date internal variable into a user-defined variable named this_month.

 

SETLEFT this_month = %date 2 ;; note: value of %date is mm-dd-yy

 

Robo-FTP script files may perform basic arithmetic operations on variables that contain numeric values. The INC and DEC commands allow incrementing and decrementing of numeric strings and the SETNUM command provides addition, subtraction, multiplication, and division. Examples of variables containing numeric values are shown below:

 

SET x = 1

SETNUM e = m x c x c ;; (hint: e = mc2)

INC x

 

Variables containing date values may be modified with the DATEADD, DATESUB, DATETIMEADD and DATETIMESUB script commands. In the following example a user-defined variable named deadline is assigned the value of the %date internal variable and  then the DATEADD command is used to add 30 days to the value of deadline.

 

SET deadline = %date

DATEADD deadline 30

 

 

Related command(s): SET, SETLEFT, SETRIGHT, SETMID, SETLEN, SETEXTRACT, SETSUBSTR, SETNUM, DEC, INC

See also: Passing External Values Into Command Scripts, Internal Script Variables