* Log onto the FTP site. FTPLOGON 'ftp.robo-ftp.com' /user=anonymous * Change the current directory on the server FTPCD 'outgoing' * Check to see if there is already a pre-existing SNAPSHOT database * If so, we can skip the "do_snapshot" routine, which creates that database IFFILE "ftpsnapshot_test.sql" GOTO do_diff :do_snapshot * Take a snapshot of the current directory * This isn't necessary with every run FTPSNAPSHOT "" "ftpsnapshot_test.sql" * Check to see if there was an error in creating the snapshot. IFERROR GOTO error_in_snapshot :do_diff * Check the site for changes. FTPDIFF "*" "ftpsnapshot_test.sql" * Check for an error in the DIFF command IFERROR GOTO error_in_diff * If there are differences, then download files IFNUM> %ftpdifffiles 00 GOTO do_getdiff * Otherwise, finish the script GOTO done :do_getdiff * First, do a rewind to make sure you are looking at the first difference FTPDIFFREWIND :download_files * Check the next difference FTPGETDIFF "ftpsnapshot_test.sql" * An EOF error indicates that all files have been downloaded; exit the loop IFERROR= $ERROR_READ_EOF GOTO download_complete * Any other error indicates that something went wrong when checking the * database, so we need to check for that error IFERROR GOTO error_in_getdiff * if the difference is $DIFF_FILE_NOT_FOUND, do not delete the file, skip this * file and go back to the top of the loop IFNUM= %ftpdifffileid 5001 GOTO download_files * the other difference types indicate that the site file is new or has changed, * so let's download it RCVFILE %ftpdifffilename * check for an error when downloading IFERROR GOTO error_in_download * move on to the next difference GOTO download_files :download_complete * do another diff, to see if anything changed while we were downloading files * in most cases, there will be no more differences, and the do_diff procedure * will simply exit to the "done" label. GOTO do_diff :error_in_download * You would normally place any error handling in this section. For the sake * of brevity, we have omitted any specific error handling. * You script should respond to download errors. Download errors are typically * caused by networking issues, or file read/write permissions * Common error-handling includes: * logging off the server and logging back on, then trying to download again * writing a test file to the database location, to check for file read/write errors * reporting the error to an administrator, usually via email * logging off the server and ending script execution :error_in_snapshot * You would normally place any error handling in this section. For the sake * of brevity, we have omitted any specific error handling. * You script should respond to FTPSNAPSHOT errors. Since FTPSNAPSHOT is creating * a database of information from the server, errors can come either * from an error in getting server information or in writing that information to disk. :error_in_diff * You would normally place any error handling in this section. For the sake * of brevity, we have omitted any specific error handling. * You script should respond to FTPDIFF errors. Since FTPDIFF is comparing a * database of information to the current conditions in the server, the most * frequent cause for an error hear is either a problem in the database file, * or a problem getting information to the server. :error_in_getdiff * You would normally place any error handling in this section. For the sake * of brevity, we have omitted any specific error handling. * You script should respond to FTPGETDIFF errors. FTPGETDIFF errors indicate * a problem retrieving information from the FTPDIFF database :done FTPLOGOFF * Bye