Operators
Operators are ScriptFTP symbols used for performing arithmetical or logical operations, there are also operators for comparison and text string concatenation. The behavior of operators, like in any othe programming language, is very similar to commands. They usually take two values or variables and return one. The operators supported by ScriptFTP are the following:
Arithmetical operators
- + Sum.
- – Substract.
- * Multiply.
- / Divide.
As the ScriptFTP language is intended for batch operations and automatic transfers, more complex operations such as square roots or powers are not supported.
# Assign 32 to the $A variable $A="32" # Assign 1 to the $B variable $B="1" # $C is the sum of $A and $B $C=$a+$B # $D is the result of substracting 1 to $A $D=$A-1 # Multiplying 5 and 7 you get $E $E=5*7 # The use of parenthesis is also allowed: $F=($A+(100/$C)-2)*5 # If you try to use a text value in an arithmethical # expression it's interpreted as a zero: $thisiszero= 5*"abcdef"
Comparison operators
- < Less than.
- > Greater than.
- <= Less or equal than.
- >= Greater or equal than.
- == Equal.
- != Not equal.
The ScriptFTP language is typeless. There are no data types and every value is stored as a text string, even numbers. Every logical operation like the IF statement or the logical operators below rely on the interpretation of true as the text “TRUE” and false as “FALSE”. This means that the logical operators will indeed return a text value containing “TRUE” or “FALSE”. Let’s see an example:
# Store 4 in the variable $A $A=4 # Store 3 in the variable $B $B=3 # Is $B greater than $A? Store the result in $R $R= $B > $A # Show the content of $R in the ScriptFTP window # FALSE should be printed PRINT($R) # If $B was greater than $A show a message, else show other message IF($R) PRINT("The value stored in $B is greater than the one stored in $A") ELSE PRINT("The value stored in $B is not greater than the one stored in $A") END IF # You should see the second message
Logical operators
- AND Logical AND operation.
- OR Logical OR operation.
The logical operators returns “TRUE” or “FALSE”, this is because, as stated before, ScriptFTP language is typeless. Every value is stored as text and the logical values true or false are stored as “TRUE” or “FALSE” respectively.
# Assign some values: $A=-5 $mytext="abcdef" # If $a is less or equal than 4 and $mytext is equal to "abcdef" # show a message in the ScriptFTP window IF(($A <= 4) AND ($mytext=="abcdef")) PRINT("Both conditions were true") END IF # Assign to $mylogicalvalue the result of # two comparisons combined with the OR operator $mylogicalvalue= (3 > $a) OR (4 < 2) # As the first comparison is true and the second # is false, $mylogicalvalue should store "TRUE" PRINT($mylogicalvalue) #Connect to the server and upload three files OPENHOST("ftp.myhost.com","myuser","123456") $result1=PUTFILE("C:\My Documents\notes.txt") $result2=PUTFILE("C:\theotherfile.txt") $result3=PUTFILE("C:\backup.zip") CLOSEHOST() # Check if an error ocurred: # If result1 is different than "OK" or # result2 is different than "OK" or # result3 is different than "OK" show an error IF(($result1!="OK") OR ($result2!="OK") OR ($result2!="OK")) PRINT("An error was found uploading files") ELSE PRINT("Files uploaded correctly") END IF
Text value operators
- . Concatenate two values or variables.
$text1="this" $text2="is" $text3="ScriptFTP" # Show "thisisScriptFTP" on the ScriptFTP window $complete_text_without_spaces=$text1.$text2.$text3 PRINT($complete_text_without_spaces) # Show "this is ScriptFTP" on the ScriptFTP window $complete_text_with_spaces=$text1." ".$text2." ".$text3 PRINT($complete_text_with_spaces) # Print "Hello World!" three times on the ScriptFTP window PRINT("Hello World!") PRINT("Hello"." "."World!") PRINT("He"."llo"." Wo"."rld!")