Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
OK, you haven't said whether you have access to the user account on the server. If you do, can you run things from crontab there? Or do you need to cleanup the directory via remotely logging in via FTP? –  Philip Reynolds Nov 9 '09 at 10:43
Thanks for questions. I've edited original post –  Deem3n Nov 9 '09 at 12:52

1 Answer 1

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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