Using Variables in Command Options

Top  Previous  Next

 

Unlike script command arguments, Robo-FTP script command options may not be specified using variables directly. The following is an example of a script command with an option:

 

FTPLOGON /pw=password

 

In this case password is a literal string (without quotation marks) and it cannot be replaced with a variable. However, there is an indirect way that this can be done. This involves the building of a complete command in a variable and using the PERFORM script command to run it.

 

For example, let's assume that you wish to log on to an FTP site but the user name and password of the FTP site is not known until the script is run. The command to logon on might look like the following:

 

FTPLOGON /user=thisuser /pw=password

 

Say that the script prompts the user for their user name and password, and these are assigned to script variables uname and pword. You might be inclined to try something like:

 

FTPLOGON /user=uname /pw=pword ;; Wrong!

 

This will result in the wrong user name and password (the variable names, not their values) being sent to the FTP site. The supported method would be:

 

SET cmd = "FTPLOGON /user=" & uname & " /pw=" & pword

PERFORM cmd

 

When using this approach there are some situations that cause problems with the command parser. If, for example, the user name contained a space character like "Sam Smith" then the command parser will evaluate the user name as "Sam" and then produce and error because "Smith" is an invalid argument. Variables that contains file names and paths are another situation where the value of the variable is likely to contain space characters. A related problem could occur if the password contains either an asterisk or semi-colon because the command parser will see the remainder of the line as a comment which will result in a login failure. In  situations like these you should use the single quote character to delimit the values inside the command string like this:

 

SET cmd = "FTPLOGON /user='" & uname & "' /pw='" & pword & "'"

 

In another example, let's assume that you wish to control the reading of a text file using the READFILE command with /record option, but the record number varies and you wish to use a variable to specify which record to read. Normally the command would look something like the following:

 

READFILE "datafile" datarecord /record=1

 

The /record option accepts a numeric constant only. Using a variable, you would like do something like:

 

SETNUM rec = 10

READFILE "datafile" datarecord /record=rec ;; WRONG!!

 

The supported method is:

 

SET file = "datafile"

SETNUM rec = 10

SET cmd = "READFILE " & file & " /record=" & rec

PERFORM cmd

 

This method may be used on any Robo-FTP script command that uses options.

 

 

See also: Script File Command Options