Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

My backups are stored on remote FTP server. I'm looking for a universal way to clean-up the FTP directory using bash or python.

Any help would be appreciated.

Edited: I have only FTP access to the server.

I need to cleanup the directory via remotely logging in via FTP

share|improve this question

marked as duplicate by Andrew Schulman, MadHatter, HBruijn, Jenny D, mdpc Jun 10 '15 at 0:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

You need to provide more information to get meaningful help.

At least:

  • How do you access the server? Do you have a direct (SSH or similar) shell connection, or are you limited to FTP? Can you install cron entries on the server?
  • How do you want to purge? Everything older than X days? When exceeding a certain size limit (dangerous)? ...?

That said, some pointers:

  • If you can run your script locally (via SSH from somewhere else, or via crontab, things will be easier). Then you can just write a script that deletes locally based on your criteria. You might even get away with standard software, e.g. using logrotate (standard Linux utiliy) to rotate & delete old backups.
  • If you must go through FTP, you can use some helper library. Python has ftplib to use FTP from Python. Even better, mount the FTP server as a local dir using some mechanism like FUSE / CurlFtpFs.
  • You might want to consider switching to some more secure mechanism like SFTP or FTP-SSL for server access. These would also be somewhat easier to script.
share|improve this answer
Thanks for questions. I am limited only to FTP. Regarding purge: after clean-up should remain only last X backups – Deem3n Nov 9 '09 at 12:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.