Back to blog

How to Delete Files on SFTP via Zapier

Delete files from SFTP/FTP/S3 as part of your Zapier automation using PushFTP.

·5 min read

Why Delete Files Remotely?

After processing a file — parsing its data, forwarding it, archiving it — you often want to clean up the original. Leaving processed files in place clutters directories, wastes storage, and risks reprocessing. PushFTP's Delete File action in Zapier lets you remove files from SFTP, FTP, or S3 as part of your automated workflow.

All operations go through PushFTP's fixed IP address, so your firewall rules don't need to change.

What You Need

  • A PushFTP account with a connection (sign up free)
  • PushFTP's static IP whitelisted on your server
  • A Zapier account
  • Write/delete permissions on the remote directory

Step 1: Choose Your Trigger

Deletion usually comes at the end of a workflow. Common triggers:

File was just processed:

Trigger: PushFTP → New File Detected
Action 1: PushFTP → Download File
Action 2: (process the file)
Action 3: PushFTP → Delete File  ← the cleanup step

Scheduled cleanup:

Trigger: Schedule → Every Sunday at midnight
Action 1: PushFTP → List Files in /temp/
Action 2: Loop through results
Action 3: PushFTP → Delete File for each

External trigger:

Trigger: Webhooks → POST from your backend
Action: PushFTP → Delete File

Step 2: Add the Delete File Action

In your Zap, add a new action:

  1. App: PushFTP
  2. Event: Delete File
  3. Account: Your PushFTP account

Configure:

Connection: My SFTP Server
Remote Path: /incoming/processed-invoice.pdf

Or map it dynamically:

Remote Path: {{path}} (from trigger or previous step)

Step 3: Test It

Create a test file on your server:

echo "delete me" | sftp user@server:/test/ <<< "put /dev/stdin test-delete.txt"

Set the Delete File action to target /test/test-delete.txt and run the test. Verify the file is gone from your server.

Common Deletion Workflows

Process Then Delete

The most common pattern — download the file, do something with it, then delete the original:

Trigger: PushFTP → New File Detected (/incoming/)
Action 1: PushFTP → Download File
Action 2: Google Sheets → Create Row (from parsed data)
Action 3: PushFTP → Delete File
  Path: {{path from trigger}}

Process Then Move (Safer Alternative)

If you're nervous about deleting, move the file instead. You can always delete later:

Trigger: PushFTP → New File Detected (/incoming/)
Action 1: PushFTP → Download File
Action 2: (process)
Action 3: PushFTP → Move File
  From: {{path}}
  To: /archive/{date}-{original}

See the move and rename guide for details. You can then run a separate scheduled Zap to clean up the archive folder periodically.

Scheduled Directory Cleanup

Clean out old files on a schedule:

Trigger: Schedule → Every Day at 2am
Action 1: PushFTP → List Files
  Path: /temp/
Action 2: Filter → Only continue if file count > 0
Action 3: Loop → For each file
  Action 3a: PushFTP → Delete File
    Path: /temp/{{filename}}

This keeps your temp directories from growing indefinitely. Check the Zapier integration docs for how to set up loops.

Safety Tips

Deletion is permanent on most servers. A few precautions:

  1. Test with a junk file first — never test delete actions on production data
  2. Add a filter step — only delete files matching specific patterns (e.g., *.processed, older than X days)
  3. Consider move instead of delete — archive first, clean up later
  4. Check your Zap history — Zapier logs every action, so you can see what was deleted and when
  5. Use descriptive file paths — map the path from a trigger rather than hardcoding, so you always delete the right file

Deleting From S3

Same action, different connection. For S3, the path is the object key:

Connection: My S3 Bucket
Remote Path: temp/uploads/old-report.csv

S3 deletions are immediate and permanent (unless you have versioning enabled on the bucket). PushFTP connects through its static IP, which works with S3 bucket policies that restrict access by IP.

Error Handling

What happens when deletion fails?

  • File doesn't exist — the action fails. Add a Find File step first if the file might not be there
  • Permission denied — the SFTP user doesn't have delete permissions on that directory. Fix server-side permissions
  • Directory not empty — you can't delete a directory with files in it. Delete the contents first
  • Connection failed — PushFTP's IP might not be whitelisted, or the server is down

For critical workflows, add PushFTP's Transfer Failed trigger to a separate Zap so you get notified about failures. See the failure alerts guide.

Automated cleanup keeps your servers organized and prevents reprocessing. One Delete File action in your Zap, and processed files are gone — no manual housekeeping, no accumulating clutter.

FAQ

Can I delete entire directories?

The Delete File action removes individual files. To delete a directory, you need to delete all files inside it first (using List Files + Loop + Delete File), then the empty directory can be removed. PushFTP's SSH command action can also handle this if your connection supports it.

Is there an undo for deleted files?

No. Once deleted from the remote server, the file is gone (unless your server has backups or S3 versioning). If you need a safety net, use Move File to archive before deleting.

Can I delete files matching a pattern (e.g., *.tmp)?

The Delete File action takes an exact path. To delete by pattern, use List Files first to get all filenames, filter them in Zapier, then loop through the matches with Delete File.

Does deletion count as a transfer?

Yes. Each Delete File operation counts as one transfer toward your monthly quota on the free plan (50 transfers). On paid plans, transfers are unlimited.

Clean As You Go

Deletion is the cleanup step that keeps your file workflows tidy. Whether you're removing processed invoices, clearing temp directories, or enforcing retention policies, the Delete File action handles it as part of your automated pipeline. Pair it with PushFTP's other actions — download, read, move — and your file management runs itself.

Ready to automate your file transfers?

Connect to any SFTP, FTP, or S3 server from a fixed IP address. Free plan available — no credit card required.