Local and FTP Site Snapshots and Finding New or Changed Files

Top  Previous  Next

 

Robo-FTP offers a series of commands to identify change(s) made to one or more files within a given folder or directory structure within both the local PC and FTP site file system.

 

This identification process consists of three steps: (1) establish a baseline for the file system (referred to as taking a snapshot); (2) determine the difference(s) at some future time by comparing the current state of the file system against the snapshot; and (3) report the differences found, sequentially file by file, in a manner suitable for script processing.

 

The snapshot step is usually only required to be performed once because subsequent differences steps automatically update the snapshot unless this is specifically disabled.

 

The three steps described above translate directly into six Robo-FTP script commands, three each for local PC and FTP site file systems.

 

SNAPSHOT and FTPSNAPSHOT are the local and site commands, respectively, that create the baseline file system snapshots. These commands operate at the current folder/directory level or can be instructed to descend and traverse all subfolders/subdirectories as they are found. Details about the files found are saved in an SQL-style database which constitutes the “snapshot”. The completion of these commands, especially FTPSNAPSHOT, can take a considerable period of time depending on how many files are present.

 

The total number of files examined in the local or FTP site file system are saved in the %snapshotfiles or %ftpsnapshotfiles script variables, respectively.

 

;;Take complete snapshot within current folder and

;;save to default snapshot database "snapshot_local.sql"

SNAPSHOT "*"

 

;;Take complete snapshot within current folder and all

;;subfolders and save to specified snapshot database

SNAPSHOT "*" "mydatabase.db" /incldirs

 

Once a snapshot has been taken, DIFF and FTPDIFF are the local and site commands, respectively, that compares the current state of the file system with the snapshot. Again, as with SNAPSHOT and FTPSNAPSHOT, these commands operate at the current folder/directory level or can be instructed to descend and traverse all subfolder/subdirectories as they are found. Details about any differences found (i.e., new files found, file size changes, date/time stamp changes) that are found are saved in the same SQL-style database. The completion of these commands too, especially FTPDIFF, can take a considerable period of time depending on how many files are present. Once a difference is noted in the database, the original snapshot record is also updated to reflect the newly found state of a given file. (This update can be suppressed under script control if you wish the original snapshot to remain unaltered.)

 

The total number of differences found in the local or FTP site file system are saved in the %difffiles or %ftpdifffiles script variables, respectively.

 

The final step is to obtain the difference(s) found in the previous step and utilize file name(s) in some meaningful way within your Robo-FTP script. GETDIFF and FTPGETDIFF are the local and site commands, respectively, to sequentially (in file system order) obtain file name(s) and text description of each difference found. (File system order means that it is possible for file(s) in subfolders/subdirectories to be reported before all files in a higher order folder/directory level(s) are reported - this would result from an alphabetic listing of file and subdirectory names at a given level.)

 

When GETDIFF is called, the file name found is returned in the %difffilename script variable, the full path name in %difffilepath, a description of the difference is found returned in the %difffiletext script variable, and a numeric representation is in the %difffileid script variable. The corresponding variables for FTPGETDIFF are %ftpdifffilename, %ftpdifffilepath , %ftpdifffiletext, and %ftpdifffileid respectively. Finally, the sequential file number for a given difference is returned in the %diffnum and %ftpdiffnum script variables.

 

The possible differences are:

$DIFF_FILE_NOT_FOUND

5001

** File not found

$DIFF_FILE_IS_NEW

5002

** File is new

$DIFF_FILE_SIZE

5003

** File size has changed

$DIFF_FILE_DATETTIME

5004

** File date/time stamp has changed

 

Two additional script commands, DIFFREWIND and FTPDIFFREWIND, are used to “rewind” the differences lookup if you ever wish to have GETDIFF or FTPGETDIFF, respectively, start over from the beginning of the differences database. The differences returned by GETDIFF or FTPGETDIFF will not change until the DIFF or FTPDIFF commands are reissued.

 

What follows is a simple example where all differences found are written to a text file.

 

DIFF "*"

:loop

GETDIFF

IFERROR $ERROR_READ_EOF GOTO done

SET Diff = "File: " + %difffilepath + " " + %difffiletext

WRITEFILE "differences.txt" Diff /append

GOTO loop

:done

 

For more information see the descriptions of the various script commands.