Linux – Delete all files inside a directory over FTP with BASH

bashftplinux

I try to delete all files from a directory on a remote FTP server with BASH. I was only able to delete the files and the folder, but not just clearing a folder out.. :/

Best Answer

From the ftp man page:

mdelete [remote-files] Delete the remote-files on the remote machine.

So you should be able to connect to your ftp server, navigate to the proper directory, and then mdelete the desired files:

ftp nobody@ftp.example.com
cd my_local_directory
prompt
mdelete *.txt~

The prompt command tells your ftp client not to ask you for a confirm each time.