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.