Monitoring a directory and using variable substitution

You can monitor a directory using the fteCreateMonitor command. The value of a substitution variable can be substituted in the task XML definition and used to define the transfer behavior.

About this task

In this example, the source agent is called AGENT_HOP. The directory that AGENT_HOP monitors is called /test/monitored. The agent polls the directory every 5 minutes.

After a .zip file is written to the directory, the application that writes the file to the directory writes a trigger file to the same directory. The name of the trigger file is the same as the name of the .zip file, but has a different file extension. For example, after the file file1.zip is written to the directory, the file file1.go is written to the directory. The resource monitor monitors the directory for files that match the pattern *.go then uses variable substitution to request a transfer of the associated .zip file.

Procedure

  1. Create the task XML that defines the task that the monitor performs when it is triggered.
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <request version="4.00" 
             xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
             xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
       <managedTransfer>
         <originator>
           <hostName>blue.example.com</hostName>
           <userID>USER1</userID>
         </originator>
         <sourceAgent agent="AGENT_HOP" QMgr="QM_HOP"/>
         <destinationAgent agent="AGENT_SKIP" QMgr="QM_SKIP"/>
         <transferSet>
           <item mode="binary" checksumMethod="none">
             <source>
               <file>/test/monitored/${fileName{token=1}{separator=.}}.zip</file>
             </source>
             <destination type="file" exist="overwrite">
               <file>/out/${fileName{token=1}{separator=.}}.zip</file>
             </destination>
           </item>
         </transferSet>
       </managedTransfer>
    </request>
    

    The variables that are replaced with the values associated with the trigger file are highlighted in bold. This task XML is saved to the file /home/USER1/task.xml

  2. Create a resource monitor to monitor the directory /test/monitored.
    Submit the following command:
    
    fteCreateMonitor -ma AGENT_HOP -mm QM_HOP -md /test/monitored 
                     -mn myMonitor -mt /home/USER1/task.xml 
                     -tr match,*.go -pi 5 -pu minutes
    
  3. A user or program writes the file jump.zip to the directory /test/monitored, then writes the file jump.go to the directory.
  4. The monitor is triggered by the existence of the file jump.go. The agent substitutes the information about the trigger file into the task XML.
    This results in the task XML being transformed to:
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <request version="4.00" 
             xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
             xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
       <managedTransfer>
         <originator>
           <hostName>blue.example.com</hostName>
           <userID>USER1</userID>
         </originator>
         <sourceAgent agent="AGENT_HOP" QMgr="QM_HOP"/>
         <destinationAgent agent="AGENT_SKIP" QMgr="QM_SKIP"/>
         <transferSet>
           <item mode="binary" checksumMethod="none">
             <source>
               <file>/test/monitored/jump.zip</file>
             </source>
             <destination type="file" exist="overwrite">
               <file>/out/jump.zip</file>
             </destination>
           </item>
         </transferSet>
       </managedTransfer>
    </request>
    

Results

The transfer defined by the task XML is performed. The jump.zip file is read from the /test/monitored directory by AGENT_HOP and is transferred to a file called /out/jump.zip located on the system where AGENT_SKIP is running.