If you have done some programming before you will probably be familiar with the term “variable”. However, this tutorial is intended to teach the concept of variables from the ground up. So here is a definition: “A variable is a language item to store something”. In ScriptFTP that something means just text. Let us look at an example:

# Store the text Hello world in myvariable
$myvariable="Hello world"
 
# Print Hello world in the ScriptFTP window
PRINT($myvariable)

The output of the script is the following:

Hello world

A variable does not need to be declared before use. In other words, you do not need to state explicitly in your script that the word “my_number” is a variable you are going to use. Just use the variable. The only restriction on variable names is that command names are not allowed.

You can use variables for storing the parameters of a command and then call the command using these variables.

$host="ftp.myhost.com"
$user="myuser"
$password="123456"
 
OPENHOST($host,$user,$password)
PUTFILE("*.*",SUBDIRS)
CLOSEHOST

Variables may also be used to store the value a command returns:

# Connect to server and store the
# return value of OPENHOST in $result
$result=OPENHOST(host,user,password)
 
# If the result is "OK" transfer the
# files and disconnect
IF($result=="OK")
PUTFILE("*.*",SUBDIRS)
CLOSEHOST
END IF

Just like commands ScriptFTP features a set of operators for calculating arithmetical or logical expressions. In the above example we used the == operator in order to check whether the content of the variable is equal to “OK”. Operators also include +,-,*,/ among others. Have a look at Operators for more information.

The use of IF is also described in the next section. See also Error handling.

As mentioned before every ScriptFTP variable holds a text string and therefore it is necessary to enclose the text with quotes, however, if you supply a number, the quotes may be omitted.

$myvariable=1
PRINT($myvariable)
PRINT("2")
PRINT(-3)

The script output is:

1
2
-3

Next Lesson: IF, WHILE and GOTO