Script Actions and Independence

The first thing to understand about scripts is that all file and program execution actions are independent of one another.  When a script is processed, the various actions defined in the script are placed into queues for processing.  They are released from the queues based on time, and are limited only by the maximum server and transfer values defined for the script.  The order of the actions as they are written in the script may not correspond to the order in which they are processed.  Consider a simple example where you wish to transfer a file and then delete the original. You might program this as follows:

          :From: C:\Source\Test.file
          :To:      {ftp:Server}C:\Target\Test.file

          :Delete_Files:C:\Source\Test.file

Both actions are queued for immediate processing.  The transfer is started, and the delete is processed immediately after the transfer begins.  If the transfer process is quick enough, the delete may work and the script performs as you expect.  If the file is large and gets opened quickly, the delete may find it in use and fail.  If the transfer task does not get the file opened quickly, the delete may work and the transfer may fail since the source file is now missing.  In other words, the results are unpredictable.

Independence allows Beyond FTP to process multiple actions simultaneously, to retry failed actions while continuing to “keep the ball rolling” by processing later actions during the time the retried entries are waiting, and to efficiently manage transfers to more than one server.  The drawback is that it requires the script designer to be aware of those situations where a specific order must be maintained.  The general rule is this:

All script actions are asynchronous unless synchronous behavior is specifically enforced. 

In the above example, we need a way to control the transfer and the delete so that they are processed in the correct order.  This can be easily accomplished using the Wait_For_Completion command as follows:

          :From: C:\Source\Test.file
          :To:      {ftp:Server}C:\Target\Test.file

          :Wait_For_Completion:

          :Delete_Files:C:\Source\Test.file

However, the delete will be processed regardless of the completion status of the transfer.  This means the file is removed even when it has not been moved successfully.  A better solution is to test for that completion status as discussed in the next topic.