Call now to talk to an automation expert — (512) 345-2211

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.


download_complete_files.s

Download

When downloading files from an FTP server, it is possible to encounter a situation where you end up downloading a file that is still being updated by some other process on the server.

The FTP protocol does not offer a way to detect whether a file on a server is in use. This problem is usually avoided one of three ways:

  • The FTP server detects files in use and returns an error that Robo-FTP (or any client) can handle
  • The process on the server is designed to avoid this by creating files in a temp directory and then moving them to the server directory (a file move is usually an atomic process on most operating systems).
  • The server and client agree on some method for locking files (usually by creating and deleting temp files or directories to create a lock)

How do you solve this kind of problem in cases where the process on the server has not been designed to prevent this situation, and you have no control over changing the server process?

The answer is to add logic to your script to try to detect files that are changing.

This sample script checks a file's size, pauses for a second, then checks the size again. If it sees the file size is changing then it waits a while then tries again.

This method is not 100% guaranteed to avoid conflicts, but is sufficient for most applications.

Version 3.9.7 and later

Starting with version 3.9.7 the RCVFILE command supports an option named /skip_changing that can be used to implement this behavior in one line of script. Please see the Help file for details.


  1  ftplogon "mysite"
  2  :try_again
  3  getsitefile "*"
  4  IFERROR= $error_no_file_found GOTO done
  5  set size1 = %sitefilesize
  6  pause /for=1
  7  getsitefile %sitefile
  8  set size2 = %sitefilesize
  9  IFNUM!= size1 size2 goto pause_and_try_again
 10  rcvfile %sitefile
 11  goto done
 12  :pause_and_try_again
 13  pause /for=5
 14  goto try_again
 15  :done
 16  FTPLOGOFF
 17  exit

Browse complete list of scripts

Need help figuring out where to start?

Our sales staff is available to answer product questions and help you determine if Robo-FTP is a good match for your project.

Call Now: (512) 345-2211