Comparing Local and Remote Files |
Top Previous Next |
Robo-FTP provides a set of commands and variables permitting size and date/time of local and FTP site files to be compared. Comparisons may be made from the point of view of the local PC compared to the FTP site (using the FILECOMPARETO command) or from the point of view of the FTP site compared to the PC (using the FILECOMPAREFROM command). The IFDATE and IFSIZE conditional commands are used to test the results of the comparisons.
The FILECOMPARETO and FILECOMPAREFROM commands really do not do anything different. They merely return different result codes depending on their point of view. The FILECOMPARETO command essentially asks compare the specified local file to a file of the same name on the FTP site and report if the file on the FTP site is larger, older, the same size, etc. The FILECOMPAREFROM command does the opposite and reports if a local file that matches the specified name of a file on the FTP site is larger, smaller, etc. than the file on the FTP site.
The results of the comparisons are saved into the %comparesize and %comparedate internal variables.
Possible result codes stored in %comparesize for the FILECOMPARETO command are listed below:
Possible result codes stored in %comparedate for the FILECOMPARETO command are listed below:
Possible result codes stored in %comparesize for the FILECOMPAREFROM command are listed below:
Possible result codes stored in %comparedate for the FILECOMPAREFROM command are listed below:
The %comparesize and %comparedate variables are specifically tested using the IFSIZE and IFDATETIME commands. These variables contain the result code from comparing the size of a local file and a file on the FTP site (%comparesize) and from comparing the date/time stamps of a local and FTP site file (%comparedate). Otherwise, these variables are no different from other internal script variables and may be used in other script commands as may be necessary.
Consider the following example that branches if a file on an FTP site is found to be larger than a local file of the same name.
FILECOMPARETO "localfile.txt" IFSIZE $ERROR_SRVR_FILE_LARGER GOTO server_larger
The following example branches if a local file is found to be older than a file of the same name on the FTP site.
FILECOMPAREFROM "serverfile.txt" IFDATE $ERROR_LOCAL_FILE_OLDER GOTO local_older
Compound comparisons, such as if a file newer and larger, requires multiple tests as shown below.
FILECOMPARETO "localfile.txt" IFDATE $ERROR_FILES_SAMEDATETIME GOTO no_match IFDATE $ERROR_SRVR FILE_OLDER GOTO no_match IFSIZE $ERROR_FILES_SAME_SIZE GOTO no_match IFSIZE $ERROR_SRVR_FILE_SMALLER GOTO no_match ;; local file is newer and larger
The DIFF command is available to compare the current state of a local folder with its previous state and the FTPDIFF command is its equivalent for folders on remote sites.
Related command(s): FILECOMPARETO, FILECOMPAREFROM, IFDATE, IFSIZE See also: Using the %date, %datetime, and %time Variables, Comparing File Dates and Times |