44

I am connected to a Unix server and I am trying to, via FTP, delete the directory dir with several files in it. If I use

ftp> delete dir/*

I get

550 Wildcard is ambiguous.

When I use

ftp> prompt off
Interactive mode off.
ftp> mdelete dir/*

I still get

550 Wildcard is ambiguous.

When I try

ftp> glob
Globbing on.
ftp> mdelete dir

I'm prompted for every file.

How can I easily delete/empty-and-delete a directory without getting prompted for every file?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
JonatanEkstedt
  • 905
  • 1
  • 8
  • 27

6 Answers6

45

I got it to work in two steps, on a server with restricted access, no SFTP, only FTP through commandline.

Like this :

mdelete folder_name/*
rmdir folder_name
EcchiOli
  • 802
  • 9
  • 11
19

If you've hidden files or folders on your server (for example .folder), you have to set the lftp list-options to "-a".

So this worked for me:

$ lftp -u user,pass server
> set ftp:list-options -a
> cd /folder/to/be/empty/
/folder/to/be/empty/> glob -a rm -r *
philsch
  • 1,004
  • 11
  • 19
  • 3
    See also [this answer](http://serverfault.com/questions/221436/delete-recursive-directories-with-ftp-command-on-bash) on Serverfault. And [this](http://happy-coding.com/transfer-a-file-to-a-remote-server-using-lftp/). `lftp -u login,password ftp_server_location -e "rm -r directory_to_delete; exit"` – chaserx Jul 19 '13 at 19:36
  • 1
    My favorite answer, lftp is so much easier. – Jim Oct 06 '13 at 01:11
  • 1
    It's too bad `lftp` doesn't remove all the files in a folder as one request. It seems to do a round trip for every single file, so it's very slow. – joeytwiddle Jul 05 '15 at 15:53
  • 1
    @joeytwiddle That's not `lftp` fault. It is a limitation of the FTP protocol. – Martin Prikryl Sep 18 '19 at 10:36
18

Use lftp to log into your server, this supports the rm -r command.

lftp user, password server

then:

rm -r directory

the -r stands for "recursive".

info:

StaNov
  • 332
  • 1
  • 4
  • 17
Bulki
  • 734
  • 1
  • 10
  • 30
4

$ ftp -i ...

will turn off prompting on mdel, which is what you want. It can't be done inside ftp.

Mike Duffy
  • 49
  • 2
0

rmdir directoryName

this directory must be in the current directory however.

cheatsheet: http://www.cs.colostate.edu/helpdocs/ftp.html

Bulki
  • 734
  • 1
  • 10
  • 30
0

I'm using Filezilla, and it deletes folders recursively. I believe the ftp does not have a command that recursively deletes folders.

Terry
  • 310
  • 3
  • 9