The “Hot Receive” Feature

Top  Previous  Next

 

The GETSITEFILE and RCVFILE commands can be used together to create a service script that automatically downloads files as soon as they are added to a remote site. This type of automatic real-time processing is sometimes known as a "hot receive" process.

 

The following example polls the remote site for new files, downloads them as they appear, and then deletes them from the remote site:

 

LOG "hot_receive_script.log" /maxsize=1000

TRACELOG "hot_receive_trace.log" /maxsize=1000

WORKINGDIR "c:\download_destination_dir"

IFERROR= $ERROR_SUCCESS GOTO connect

DASHBOARDMSG "Unable to open destination folder." /status=bad

STOP ;; change STOP to EXIT before running as a service

 

:connect

DASHBOARDMSG "Connecting to remote site."

FTPLOGON "ftp.new.com" /user=anonymous /pw=itchy

 

:loop

DASHBOARDMSG "Waiting for next file."

GETSITEFILE "*" /timeout=0

IFERROR!= $ERROR_SUCCESS GOTO download_error

DASHBOARDMSG "Downloading file: " & %sitefile

RCVFILE %sitefile /delete

IFERROR!= $ERROR_SUCCESS GOTO download_error

GOTO loop

 

:download_error

DASHBOARDMSG "Problem downloading file: " & %sitefile

PAUSE /for=3 ;; give user a few seconds to read problem message

FTPLOGOFF

GOTO connect

 

Warning: This example script will download the same file repeatedly if you don't have sufficient credentials to delete files from the remote server.

 

The FTPRENAME command may be used to move the remote file out of the watched folder on the remote folder instead of simply deleting it.

 

If you do not wish to remove files from the remote site after they are downloaded you'll need a method of distinguishing new files from existing files and also for recognizing when existing files are modified.  In these situations you should use FTPDIFF and FTPGETDIFF instead of GETSITEFILE to identify and track which remote files need to be downloaded.  The FTPDIFF command also supports the the /incldirs option if you need to descend into a subdirectory tree.

 

 

See also: The "Hot Send" Feature, Using the %sitefile and %sitedir Variables, Programming Service Scripts