using bash commands and ftp connection i have to perform two tasks:

  1. delete oldest file in some directory on ftp server. name of file that have to be deleted starts with backup_
  2. delete oldest subdirectory (on ftp server) in some directory

can you help me how to achieve?

i have to integrate those functions in existing file, so i will have no problems how to create ftp connection etc.


You can use lftp as a non interactive ftp client from within the bash scripts.

Or assuming you have a fairly sane and modern distribution you could use curlftpfs FUSE filesystem to mount the ftp server folder as a local folder then use bash to do the logical bits you need to to, then unmount the ftp server.

This effectively takes away the complexity of having the files only available over ftp as the script will see the files as available locally.

There are plenty of examples available on how to delete files based on name or date, and there is an example on the curlftpfs site on how to mount and unmount file systems in scripts.


I refer to you one of those excellent tutorials at IBM,
NcFTP: The flexible FTP client;
Look at Using Command lines

The three clients ncftpls, ncftpget, and ncftpput will undoubtedly be used more than NcFTP. These utilities are very useful when you need to batch or script ad hoc transfers.

  • yes, my bad, i use ncftp. if you can help me how to delete those using ncftp, so i do not have to change my existing script... – user48058 Aug 17 '10 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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