This rule will detect a file upload to the /uploads/temp folder by a user named batch_process, and will execute a batch file operation to upload the file to another server.
Adding the New Rule
- Go to the Event Rules page of the Event Manager
- Click the New button. The Add A New Event Rule dialog will appear.
- Select the File Transfer Event Rule Type for your new rule. This event type will cause the rule to be triggered whenever a file transfer takes place.
- Enter a name for your rule in the Rule Name edit box. For example, “Forward Uploaded File”.
- Press the Add a New Rule button on the Add A New Rule dialog to save and add the new Event Rule. The event rule will be selected and ready for editing on the Edit Rules page.
Selecting a Rule Matching Mode
Select the Match If All Filters Match mode. Selecting this option means that this rule will only be triggered whenever the rule’s event occurs and if all of the conditions listed are fulfilled.
Adding the Rule Conditions
A rule’s actions are carried out whenever that rule’s event trigger happens. In this example, a File Transfer Event triggers our rule. To further limit this rule to only triggering when a file is uploaded to a specific folder, and by a specific user, we need to add three conditions or filters to the rule.
- There needs to be a filter that ensures this is an upload and not a download. To limit this rule to only triggering on an upload, select the {{D}}, Is a Download, variable from the conditions drop-down list. Select Equals as the comparison, and set the value to false.
- We also need a filter to ensure the rule only triggers when user batch_process uploads a file. Select the {{U}}, Username, variable from the conditions drop-down list. Select Equals as the comparison, and set the value to batch_process.
- Finally, we only want this rule to trigger whenever the file is uploaded to the /uploads/temp folder. Select the {{RFP}}, Remote File Path, variable from the conditions drop-down list. Select Starts With as the comparison and set the value to /uploads/temp.
Adding an executable Target to the Event Targets page
In order to upload the file to another server, we will need to execute a program on the server machine that can be invoked by Cerberus to upload the file. There are several command line clients available for command line file uploading using a variety of protocols. cURL and Psftp are two popular command line clients for uploading and downloading files. For this rule, we will use cURL to upload the file using SSH SFTP to another folder. To use cURL as part of an event rule action, we need to first add it as an available Executable target on the Event Targets page.
- Go the the Event Targets page of the Event Manager
- Click the New button on the top-right corner of the Event Targets page
- Under the Executable Target field box, select the file path to the cURL executable
- Press the Add button to the right of the Executable Path edit box to add cURL as an available event rule action target
Adding the Rule Actions
When an event matches all of the conditions of a rule then the rule actions are carried out. In this case, we want to re-upload a newly uploaded file to another server using cURL.
- Add a Launch an Executable action
- Select cURL executable path as the operation sub-action
- Enter the command line:
-k -u upload_user:test sftp://127.0.0.1/ftproot/test/{{LFN}} -T {{LFP}}
The above command line is cURL-specific, and says to login to the SFTP server at 127.0.0.1 and upload the file to /ftproot/test/ using the credentials upload_user and password test. The file name of the original uploaded file is appended to the remote path using the variable {{LFN}}, and the target file to be upload is referenced by the full local file path variable {{LFP}}. That is the full path to the file that was just uploaded – the file that kicked off this event.
To watch a video summarizing these instructions, click here.
Comments
0 comments
Please sign in to leave a comment.