GETSITEFILE        Get file and directory names from an FTP site

Top  Previous  Next

Syntax:

GETSITEFILE

[ file name ] [ /options ]

Alt Syntax:

GETSERVERFILE

 

Arguments:

[ file name ]

Variable or string defining a file name to look for; wildcard characters are allowed; this should be a file name only (do not include a directory name).

Options:

/ignorecase

Test for file name matches after forcing the local and site files to be lower case effectively making the match case-insensitive.

 

/incldirs

Return FTP site directory name(s) as they are found. (Formerly this was the /subdirs option.)

 

/newest

Get the newest file in the directory (cannot be combined with /next option).

 

/next

Get the next file in the directory; omit this option to obtain the first file from a given FTP site directory; if you wish to obtain subsequent files from this same directory, use this option until you find the desired file or no more files are found (see Important below).

 

/oldest

Get the oldest file in the directory (cannot be combined with /next option).

 

/timeout=nn

Time-out in seconds to wait for presence of the file; if this option is omitted, Robo-FTP looks for the file and if nothing is found, $ERROR_NO_FILE_FOUND is returned; otherwise $ERROR_WAIT_TIMED_OUT is returned.

 

 

This command is not valid with HTTP/HTTPS sites.

In versions prior to v1.50, this command was named GETSERVERFILE. Both are accepted.

 

This script command checks for (and optionally waits for) the existence of a file defined by the [ file name ] argument within the current directory on an FTP site. If a matching file or directory is detected, the file name is saved in the %sitefile or %sitedir variables. The date and time of the file or directory are also saved in the %sitefiledate, %sitefiledatetime, and %sitefiletime variables. The size of the file (excluding a directory), in bytes, is saved in the %sitefilesize variable.

 

The use of this command creates what is referred to as the hot receive function whereby Robo-FTP automatically retrieves files from the FTP site.

 

The /next option allows the entire contents, both files and subdirectory names, of FTP site directories to be traversed and saved in variables for use in script processing. See Displaying Files and Directories on an FTP Site for an example.  Use of this option with the /timeout option is not supported.

 

Important

For most reliable operation, use the /next option only on static server directories (i.e., where no new files are being added and none are being deleted) since each successive /next skips one file as Robo-FTP scans through a given directory. When /next is omitted, this command always returns the first file that appears in the directory (i.e., the first file that appears in the directory listing resulting from an FTP LIST command).

 

Consider the following example where Robo-FTP waits indefinitely for any file with a .rdy extension to appear on the FTP site.

 

GETSITEFILE "*.rdy" /timeout=0

 

Once such a file exists, the file name is saved in the %sitefile variable and script execution resumes.

 

Consider the following example where all the files in the current directory are retrieved from an FTP site.

 

GETSITEFILE "*.*" /timeout=2

IFERROR= $ERROR_WAIT_TIMED_OUT goto rcvd_last_file

RCVFILE %sitefile

IFERROR goto rcv_error

:label

GETSITEFILE "*.*" /timeout=2 /next

IFERROR= $ERROR_WAIT_TIMED_OUT goto rcvd_last_file

RCVFILE %sitefile

IFERROR goto rcv_error

GOTO label

:rcvd_last_file

 

The /newest and /oldest options are normally used with a wildcard [ file name ] to obtain the name of the newest or oldest file present. Use of these options with the /next option is not supported. Consider the following example where all files are retrieved from an FTP site beginning with the oldest.

 

:next_file

GETSITEFILE "*.*" /oldest

IFERROR= $ERROR_NO_FILEFOUND goto label

RCVFILE %sitefile

FTPDELETE %sitefile

GOTO next_file

:label

 

If you wish to monitor an FTP site directory other than the current directory, you must issue an FTP CWD command first to change to this directory. Consider the following example where the current directory is changed before looking for any file with a “.txt” extension.

 

FTPCD "newdir/test"

GETSITEFILE "*.txt" /timeout=2

 

The /incldirs option may be used if you wish FTP site directory names to be returned along with regular file names as they are found. When a directory is found, it is saved in the %sitedir variable and the %sitefile variable is set to an empty string. The /oldest and /newest options have no affect on the directory names returned by the GETSITEFILE command. Consider the following example that shows how directory files are distinguished from other files.

 

:look_for_directory

GETSITEFILE "*.*" /incldirs

IFERROR= $ERROR_NO_FILE_FOUND goto error

IFNSTRCMP %serverfile "" goto look_for_directory

; both %sitefile and %sitedir will not be empty at same time

DISPLAY %sitedir

GOTO look_fordirectory

:error

 

To descend into the directory returned by GETSITEFILE, you’d use the following command.

 

FTPCD %sitedir

 

The date and time of the file obtained with the command is saved to three internal variables named %sitefiledate, %sitefiledatetime, and %sitefiletime. This permits you to directly compare the file’s date and time to values of your choosing. Consider the following example that shows how a file created on a specified date after a specified time may be found.

 

:not_new

GETSITEFILE "*.*" /next

IFERROR= $ERROR_NO_FILE_FOUND goto error

SET filedatetime = "file date is " & %sitefiledatetime

DISPLAY filedatetime

IFDATE!= "06-30-02" goto not_new

IFTIME< "12.00.00" goto not_new

MESSAGEBOX "found file created after 12PM on June 30, 2002"

STOP

:error

 

Related Commands: GETNEXTFILE

See also:Using the %sitefile and %sitedir Variables,
Using the %sitefiledate, %sitefiledatetime, %sitefilesize, and %sitefiletime Variables, The Hot Receive Feature