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.


rename_with_date.s

Download

A common requirement is to download a set of files every day from a remote FTP site. This script demonstrates how to download those files and rename them so the filename includes today's date, thus providing an easy way to maintain an archive of downloaded files.

This script uses the FTPGETFILE command in a loop to download and rename files that match a wildcard pattern.

At the beginning of each loop iteration the value of the %sitefile variable is set to a new file name. Next, the SETRIGHT command is used to split the file's name from its extension. Then, the name is recombined with the value of the %date variable inserted between the name and the extension. Finally, the RCVFILE command is used with its /as option to download the file using the new name.

See the Help file for usage details for each of these commands.


  1  WORKINGDIR "c:\download\destination\folder"
  2  FTPLOGON "RemoteSite"
  3  IFERROR RETURN
  4  SET new_extension = %date + ".txt"
  5  ;; only process files matching this pattern: *.txt
  6  :start_of_loop 
  7  FTPGETFILE "*.txt"   
  8  IFERROR RETURN $ERROR_SUCCESS
  9  SETREPLACE FileName = %sitefile ".txt" new_extension
 10  ;; recombine but insert date
 11  RCVFILE %sitefile /as FileName
 12  IFERROR RETURN
 13  GOTO start_of_loop

Browse complete list of scripts