CONFIGLOAD        Load a section from a configuration file

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Script Programming > Script Commands > All Script Commands >

CONFIGLOAD        Load a section from a configuration file

Syntax:

CONFIGLOAD

[ file name ] [ section name ] [ variable name ]

Arguments:

[ file name ]

Variable or string defining the configuration file to open.

 

[ section name ]

Variable or string defining the section of the configuration file to read.

 

[ variable name ]

Optional name of a variable to assign results.

 

/raw

Disable variable substitution when reading from a configuration file

Options:

none

 

 

 

Use this script command to read in and store key/value pairs from a section in a configuration file. It creates an associative array where the key and value for each array element is set to the key and value, respectively, read from the configuration file.

 

By default, the CONFIGLOAD command sets the value in the array using the Robo-FTP SET command. This is done in order to permit variable substitution for any variables included in the configuration file. However, if that substitution fails, the raw value is used. If you wish to avoid this substitution, the /raw option will force the command to use the exact provided value, verbatim.

 

This command is for working with external configuration files. This can not be used for reading values from Robo-FTP's internal settings files.

 

For example, let's say you have the following configuration file in the current working directory named "my_config.ini."

 

[My First Section]

a_setting = some value

another_setting = some other value

 

You can load the values from "My First Section" into a variable with the following command:

 

CONFIGLOAD "my_config.ini" "My First Section" my_properties

DISPLAY my_properties[*] ;; Set to the number of properties (2 in this case)

DISPLAY my_properties[a_setting] ;; Set to 'some value'

DISPLAY my_properties[another_setting] ;; Set to 'some other value'

 

If a configuration file has settings at the top that are not under a section heading, Robo-FTP will create an element in the array for that unnamed section and set it to an empty string. For example:

 

property_not_under_a_section = a value

[First Section]

first_property = some value

second_property = some other value

 

In this case, the following command will read the property from the unnamed section:

 

CONFIGLOAD "my_config.ini" "" my_properties

DISPLAY my_properties[*] ;; Set to the number of properties (1 in this case)

DISPLAY my_properties[property_not_under_a_section] ;; Set to a value'

 

This script command also supports an alternate syntax where, if the third command argument is omitted, then a global variable is created for each key/value pair from the specified section in the configuration file.

 

This alternate syntax is not recommended for production use as there are potential risks from creating global variables based on the contents of an external file. This alternate syntax may be deprecated and removed in a future release.

 

For example, let's say you have the following configuration file in the current working directory named "my_config.ini."

 

[My First Section]

a_setting = some value

another_setting = some other value

 

You can load the values from "My First Section" from the configuration file into global variables with the following command:

 

CONFIGLOAD "my_config.ini" "My First Section"

DISPLAY a_setting ;; Set to 'some value'

DISPLAY another_setting ;; Set to 'some other value'

 

 

Related command(s): CONFIGSECTIONS

See also: Working with External Configuration Files, Arrays