FTPGETFILEARRAY         Get list of matching remote file(s)

<< Click to Display Table of Contents >>

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

FTPGETFILEARRAY         Get list of matching remote file(s)

Syntax:

FTPGETFILEARRAY

filename  varname [ /options ]

Arguments:

filename

Variable or string defining a file or path name to look for; wildcard characters allowed; If not path is defined it searches the current directory for all files

 

varname

the array name to populate.

Options:

/subdirs

Search sub-folders for files matching the [ file name ] argument.

 

/skip_changing

Ignore any file if file size is not stable for one second.

 

/skip_changing_seconds=nn

Ignore any file if the size is not stable for the specified number of seconds. Values between 1 and 60 are allowed.

 

/excludedirs=xx

Exclude all files in directories that match the name of the provided argument no matter where it appears in the path. To specify multiple directories, you can separate them with the pipe character (|) or use multiple /excludedirs options.

 

/olderthan=xx

Only retrieve changes for which the file's last modified time is older than the provided date-time (using the same format as the built-in %datetime variable).

 

/newerthan=xx

Only retrieve changes for which the file's last modified time is newer than the provided date-time (using the same format as the built-in %datetime variable).

 

/timeout=nn

Specifies the time-out in seconds to wait for presence of the file, if the timeout elapses before the file is found $ERROR_WAIT_TIMED_OUT is returned. If this option is omitted Robo-FTP looks for the file and immediately returns $ERROR_NO_FILE_FOUND if no match is found. A %datetime value can also be given as an argument instead of a number of seconds.

 

/maxfiles=nn

Limits the number of files returned to the specified value. If the /subdirs option is used, this specifies the maximum number of files returned per directory.

 

If you need to download a file please see the Help page for the RCVFILE script command.

Note

Robo-FTP offers numerous commands for monitoring for files and iterating over directory structures on local and remote servers. There is significant overlap in capabilities between these commands, but there are also important differences that often make one command better suited to a particular task than the others. Please see the chapter Monitoring for Files and Iterating over Directory Structures for a description of these commands and recommendations for which commands to use in a particular situation.

 

This script command searches the current remote directory for the file specified in the [ file name ] argument. If any matching files are found, the full path to that file is added to the array arrayname[*].

 

The /skip_changing and /skip_changing_seconds options are useful when there is a chance that a file being processed by Robo-FTP is also being modified by some other process.

 

GETFILEARRAY returns $ERROR_NO_FILE_FOUND when no file matches the [ file name ] argument. The /timeout option can be used to wait for the existence of an expected file. This is accomplished by periodically polling the folder during the waiting period. If the file does not appear before the timeout expires $ERROR_WAIT_TIMED_OUT is returned.

 

Use the FTPCD command to change the current directory before calling FTPGETFILEARRAY if the file you want to find files not in the current directory or, alternatively, the /subdirs option may be used to find files in any subdirectory of the current directory.

 

This command is especially efficient with directories containing very large numbers of files. Each call to GETSITEFILE or FTPGETFILE with wildcards must iterate over previously checked file on each call, so for very large directories or directory trees it is much faster to use FTPGETFILEARRAY and FTPGETFILE (without wildcards) together as in the following example:

 

FTPGETFILEARRAY "*" var

SETNUM counter = 0

SETNUM size = var[*]

IFNUM= size 0 GOTO loop_done  ;; skip loop if array is empty

:top_of_loop

GETSITEFILE var[counter]

IFERROR GOTO next

IFSTRCMP %sitefile "" GOTO dir

!DISPLAY %sitefile

!DISPLAY %sitepath

!DISPLAY %sitefiledatetime

!DISPLAY %sitefilesize

PAUSE /for=1

GOTO next

 

:next  

SETNUM counter = counter + 1

IFNUM< counter size GOTO top_of_loop

:loop_done

 

The FTPDIFF and FTPGETDIFF commands should generally be preferred over this command, because they are more efficient than FTPGETFILEARRAY, especially when values such as the file size or modified time need to be used, since these are automatically fetched along with the filename when using FTPDIFF. See the article on FTPGETDIFF for an example illustrating how this can be accomplished while starting with a fresh database. It is also more appropriate to use these commands where a list of unprocessed files needs to be preserved in the event of script failure, or across multiple runs of the script, since the information is preserved in a persistent external database, unlike the case with FTPGETFILEARRAY. However, FTPGETFILEARRAY can still be useful when these considerations are not relevant.

 

Important

This command returns $ERROR_NO_FILE_FOUND when no file matches the [ file name ] argument. This is not the same error as $ERROR_NO_FILES_FOUND. Please be sure to test for the correct error code.

 

 

Related command(s): GETSITEFILE, FILECOMPARETO, FILECOMPAREFROM, FTPDIFF, FTPGETDIFF

See also: Using the %sitefiledate, %sitefiledatetime, %sitefilesize, and %sitefiletime Variables, Using Wildcards, Using Arrays