Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.
download_new_files_2.s
This script uses FTPDIFF and FTPGETDIFF to check a remote site for files which have changed since the last time you checked.
Note: This sample script requires Robo-FTP 3.7 or later. If you are running an older version of Robo-FTP, please try this sample script instead: download_new_files.s.
1 * Log onto the FTP site.
2 FTPLOGON 'ftp.robo-ftp.com' /user=anonymous
3
4 * Change the current directory on the server
5 FTPCD 'outgoing'
6
7 :do_diff
8 * Check the site for changes.
9 FTPDIFF "*"
10
11 * Check for an error in the DIFF command
12 IFERROR GOTO error_in_diff
13
14 * If there are differences, then download files
15 IFNUM> %ftpdifffiles 00 GOTO do_getdiff
16
17 * Otherwise, finish the script
18 GOTO done
19
20 :do_getdiff
21 * First, do a rewind to make sure you are looking at the first difference
22 FTPDIFFREWIND
23
24 :download_files
25 * Check the next difference
26 FTPGETDIFF
27
28 * An EOF error indicates that all files have been downloaded; exit the loop
29 IFERROR= $ERROR_READ_EOF GOTO download_complete
30
31 * Any other error indicates that something went wrong when checking the
32 * database, so we need to check for that error
33 IFERROR GOTO error_in_getdiff
34
35 * if the difference is $DIFF_FILE_NOT_FOUND skip this file
36 * and go back to the top of the loop
37 IFNUM= %ftpdifffileid 5001 GOTO download_files
38
39 * the other difference types indicate that the remote file is new or has changed,
40 * so let's download it
41 RCVFILE %ftpdifffilename
42
43 * check for an error when downloading
44 IFERROR GOTO error_in_download
45
46 * move on to the next difference
47 GOTO download_files
48
49 :download_complete
50 * do another diff, to see if anything changed while we were downloading files
51 * in most cases, there will be no more differences, and the do_diff procedure
52 * will simply exit to the "done" label.
53 GOTO do_diff
54
55 :error_in_download
56 * You would normally place any error handling in this section. For the sake
57 * of brevity, we have omitted any specific error handling.
58 * Your script should respond to download errors. Download errors are typically
59 * caused by networking issues, or file read/write permissions
60 * Common error-handling includes:
61 * logging off the server and logging back on, then trying to download again
62 * reporting the error to an administrator, usually via email
63 * logging off the server and ending script execution
64
65 :error_in_diff
66 * You would normally place any error handling in this section. For the sake
67 * of brevity, we have omitted any specific error handling.
68 * You script should respond to FTPDIFF errors. Since FTPDIFF is comparing a
69 * database of information to the current conditions in the server, the most
70 * frequent cause for an error hear is either a problem in the database file,
71 * or a problem getting information to the server.
72
73 :error_in_getdiff
74 * You would normally place any error handling in this section. For the sake
75 * of brevity, we have omitted any specific error handling.
76 * You script should respond to FTPGETDIFF errors. FTPGETDIFF errors indicate
77 * a problem retrieving information from the FTPDIFF database
78
79 :done
80 FTPLOGOFF
81 * Bye

