Using Variables in Command Options

Top  Previous  Next

 

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

 

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.