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.
When everything is working perfectly (connecting to a well-behaving FTP server over a reliable network), downloading a batch of files can be as simple as:
However, sometimes you have to work in a less-than-perfect environment where connections drop without warning. This can result in downloading partial files.
This sample script shows a more reliable way to download one file at a time and automatically delete partially downloaded files. The
TMPNAME command causes files to download to a temporary name. If the download does not complete successfully the temporary file is automatically deleted. The script downloads files one at a time from the server, deleting files from the server after they have been successfully downloaded.
This is not the only way to handle this situation. For example, if you are downloading a very large file, you may not want to start over from scratch if the download fails. In that case, you may want to use the resume feature of Robo-FTP to loop back and try to resume the download at the point of failure. In that case you can simply use the /resume option on your RCVFILE command and the .partial temporary file which the file is downloaded to will be left in place so you can resume the transfer to the temporary file at a later time.
1 FTPLOGON "mysite" 2 IFERROR RETURN 3 TMPNAME "" ".partial" 4 FTPGETREWIND 5 :next 6 FTPGETFILE "*.txt" 7 IFERROR RETURN $ERROR_SUCCESS 8 RCVFILE %sitefile /delete 9 IFERROR RETURN 10 GOTO next