How To Delete A File On Your Server After It’s Downloaded

Learn how to automatically delete a file from your server as soon as its intended recipient has already downloaded it.
  1. Blog

Overview

Sometimes, for security reasons or simply just to save disk space, we want certain files to be automatically deleted from the server as soon as its intended recipient has already downloaded it. Today, you'll learn how to do that on JSCAPE MFT Server.

What we'd like to do

auto_delete_after_download

How to do it

This particular auto-deletion process entails creating a trigger that:

  1. Responds to a "File Download" event, i.e., fires as soon as a file has been downloaded from the server;
  2. Affects any downloaded file, regardless of type, user, time of download, etc.; and
  3. Executes the "Delete File" trigger action, which performs the actual file deletion.

Let's walk you through those steps now.

1. Create a new trigger

First, let's create a new trigger. To do that, go to the Triggers module and then click the Add button.

01-mft-server-auto-delete-after-download

2. Select the "File Download" trigger event type

Next, give this trigger a name, e.g. "Delete Downloaded File".

After that, select the "File Download" Event type from the drop-down list.

Click Next when you're done.

02-mft-server-auto-delete-after-download

3. Enter a trigger condition (or not)

For this example, we want the trigger to affect any downloaded file, so just enter this expression into the Trigger Conditions box.

Success = TRUE

This tells the trigger to proceed only if the download was successful.

In some cases, however, you might want to restrict the automatic file deletion process to certain downloads. For example, you might want it to apply only to: certain files, or to files downloaded by a certain user, or only during certain times, etc.

In such cases, you can specify your conditions by entering logical expressions into the Trigger Conditions box. You can view the properties pertinent to this particular trigger event whose values you can use for filtering by clicking on the Variables button.

Here are a few examples of trigger conditions you can use:

βœ” To restrict the auto deletion to jpg files:

LocalPath ~ ".*\.jpg"

βœ” To restrict the auto deletion to files downloaded by a user whose username is "johnsmith":

Username = "johnsmith"

βœ” To restrict the auto deletion to files downloaded during Mondays:

DayOfWeek = 1

You can even use a combination of these conditions to filter the trigger even further.

Click Next as soon as you're ready to proceed.

03-mft-server-auto-delete-after-download

4. Add the "Delete File" trigger action

Click the Add button.

04-mft-server-auto-delete-after-download

The trigger action we'll be needing for this particular scenario is the one named "Delete File". Select that from the drop-down list and then click OK.

05-mft-server-auto-delete-after-download

Because we want this to apply to the file that's been recently downloaded, enter the variable %LocalPath% into the box labeled File. The %LocalPath% variable holds the complete path (directory and filename) of the file that was recently downloaded.

Click OK when you're done.

06-mft-server-auto-delete-after-download

5. Finalize the trigger

Once you're back at the main screen, don't forget to click the Apply button to finalize your trigger creation process. Otherwise, this trigger won't execute.

07-mft-server-auto-delete-after-download

And you're done! Every time a user downloads a file from your server, that file will be automatically deleted.

You might also want to read...

How To Automatically Decrypt PGP-Encrypted Files Upon Upload

Using Triggers to Automate File Deletion

Rotating and Archiving Logs in JSCAPE MFT Server



What to do next

To try this out yourself, download a free evaluation of JSCAPE MFT Server now.

Download JSCAPE MFT Server Trial