The “Hot Send” Feature |
Top Previous Next |
The GETNEXTFILE and SENDFILE commands can be used together to create a service script that watches a folder on your local computer and automatically uploads any files placed into that folder to a remote site. This type of automatic real-time processing is sometimes known as a "hot send" process.
The following example watches a local folder for new files, uploads them as they appear, and then deletes them:
:find_file GETNEXTFILE "*" /timeout=0
:upload FTPLOGON "ftp.new.com" /user=anonymous /pw=itchy IFERROR!= $ERROR_SUCCESS GOTO upload_error IFERROR!= $ERROR_SUCCESS GOTO upload_error FTPLOGOFF DELETE %nextfile GOTO find_file
:upload_error FTPLOGOFF GETNEXTFILE %nextfile IFERROR= $ERROR_SUCCESS GOTO upload ; if file exists try to upload GOTO find_file ; file no longer exists so find another file
Warning: This example script will upload the same file repeatedly if you don't have sufficient credentials to delete files from the watched folder.
The MOVE or RENAME command may be used to move the uploaded file out of the watched folder instead of simply deleting it.
If you do not wish to remove files from the local folder after they are uploaded 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 DIFF and GETDIFF instead of GETNEXTFILE to identify and track which files need to be uploaded. The DIFF command also supports the the /incldirs option if you need to descend into a subdirectory tree.
Related: The "Hot Receive" Feature, Using the %nextfile, %nextpath, and %nextfolder Variables, Programming Service Scripts |