Delete all files inside a directory over FTP with BASH

3

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.. :/

Pay87

Posted 2012-07-23T17:00:32.070

Reputation: 31

rm -rf * didn't work? – qweet – 2012-07-23T17:03:07.713

Are you using an FTP client to access the remote system or SSH. Bash is simply a shell, but bash isn't used via an FTP client. – Zoredache – 2012-07-23T17:10:32.137

rm -rf * would work on local systems, but I have to delete the files over ftp (there is no ssh). I thought to use lftp or ncftp but I am not sure which one to choose. Thanks :) – Pay87 – 2012-07-23T17:12:56.463

Answers

5

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.

khoxsey

Posted 2012-07-23T17:00:32.070

Reputation: 151