Comparing Local and Remote Files

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Script Programming > Select Topics in Script Programming >

Comparing Local and Remote Files

 

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:

$ERROR_SRVR_FILE_LARGER

1226

File on server is larger

$ERROR_SRVR_FILE_SMALLER

1227

File on server is smaller

$ERROR_NO_SRVR_FILE_EXISTS

1228

File does not exist on server

$ERROR_SRVR_FILE_EMPTY

1229

File exists on server but its length is 0

$ERROR_FILES_SAME_SIZE

1234

Local and FTP site files identical in size

 

Possible result codes stored in %comparedate for the FILECOMPARETO command are listed below:

$ERROR_SRVR_FILE_NEWER

1221

File on server is newer

$ERROR_SRVR_FILE_OLDER

1222

File on server is older  

$ERROR_NO_SRVR_FILE_EXISTS

1228

File does not exist on server

$ERROR_FILES_SAME_DATETIME

1241

Local and FTP site files have same date and time

 

Possible result codes stored in %comparesize for the FILECOMPAREFROM command are listed below:

$ERROR_FILES_SAME_SIZE

1234

Local and FTP site files identical in size

$ERROR_LOCAL_FILE_LARGER

1235

Local file is larger  

$ERROR_LOCAL_FILE_SMALLER

1236

Local file is smaller

$ERROR_NO_LOCAL_FILE_EXISTS

1239

Local file does not exist

$ERROR_LOCAL_FILE_EMPTY

1240

Local file exists but length equals 0

 

Possible result codes stored in %comparedate for the FILECOMPAREFROM command are listed below:

$ERROR_LOCAL_FILE_NEWER

1232

Local file is newer

$ERROR_LOCAL_FILE_OLDER

1233

Local file is older

$ERROR_NO_LOCAL_FILE_EXISTS

1239

Local file does not exist

$ERROR_FILES_SAME_DATETIME

1241

Local and FTP site files have same date and time

 

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