Script Library

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.


upload_matching_files.s

Download

Robo-FTP's built-in support for wildcards makes it easy to process sets of files that match certain criteria.

For example, you can upload all files ending in .jpg with this command:

SENDFILE "*.jpg"

Likewise, you can upload all files that start with "abcd" with this command:

SENDFILE "abcd*"

However, what do you do in the case where you want to upload a particular set of files where part of the name matches, but you won't know ahead of time what that matching chunk of text is?

For example, consider the case where a process generates reports that consist of three files in a set like this:

my_report_part1.dat
my_report_part2.dat
my_report_part3.dat

We want to wait for all three parts of the report to be generated and then zip and upload those files to the server. We know that although the first part of the name is dynamic, it will be the same for all three parts of a report ("my_report" in this example). We also know that multiple three-part reports are being generated, so we need to make sure we upload complete reports one at a time without also accidentally uploading part of some other report.

This sample script solves this problem by using the GETNEXTFILE command several times: first we find the base name of the report we need to match, then we use it to make sure we have all three parts. The /timeout=0 option helps us wait until all three files exist. Finally, we zip and upload the report.


  1  :top
  2  ;; Find part 1 of the report and figure out the base name
  3  GETNEXTFILE "*_part1.dat" /timeout=0
  4  SET part1 = %nextfile
  5  setextract basename = part1 "_part1.dat" 1
  6  
  7  ;; Find the other 2 parts that have the same base name
  8  set part2 = basename + "_part2.dat"
  9  GETNEXTFILE part2 /timeout=0
 10  set part3 = basename + "_part3.dat"
 11  GETNEXTFILE part3 /timeout=0
 12  
 13  ;; Now that we are sure all three parts exist, zip and upload them
 14  set zipname = basename + ".zip"
 15  ZIP zipname part1 /create

 16  zip zipname part2
 17  zip zipname part3
 18  
 19  ;; Delete the files now that we have made our zip file
 20  delete part1
 21  delete part2
 22  delete part3
 23  
 24  ;; Upload and delete the zip file 
 25  ftplogon "mysite"
 26  SENDFILE zipname /delete

 27  ftplogoff
 28  
 29  ;; Go back to the top and watch for the next report
 30  goto top

Browse complete list of scripts