Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use command to delete folders in FTP?

Tags:

linux

ftp

Suppose there are some folders on FTP site:

test_20160125,test_20160222

I use the command to delete the specific folders on FTP:

ftp> rm *test_*

550 The filename, directory name, or volume label syntax is incorrect.

How can I delete the folders using FTP command?

like image 506
Luke.C Avatar asked Oct 23 '25 05:10

Luke.C


2 Answers

Use lftp protocol, also use rm -r where r option delete files and directories recursively.

$ lftp -u <user>,<pass> <server> 
lftp> rm -r <directory>

The ftp(1) command-line client translates its built-in rm command into the FTP DELE command, and most FTP servers handle DELE (DELEte File) by calling the function for deleting a file (e.g. unlink(2) on Unix), not a directory. Thus you might try:

ftp> rmdir *test_*

However, even the above would probably fail, as the client-side rmdir command would be translated to the FTP RMD (ReMove Directory) command; many FTP servers handle RMD by calling e.g. the rmdir(2) function. Some FTP servers would not handle the RMD parameter as a glob pattern, and thus might try to delete a directory named exactly "test_" (which presumably does not exist). And even if the glob pattern was handled, attempting to delete a directory which contains files often fails; the files in the directory need to be deleted first.

Thus you might need to delete the files in those directories, then delete the directories themselves:

ftp> mdelete test_*/*

The client-side mdelete command should, behind the scenes, do the necessary glob/pattern matching for you, and delete the files matching the pattern. Then you might remove those directories using:

ftp> rmdir test_20160125
ftp> rmdir test_20160222

Since functionality of this nature is often done in the client, using a more sophisticated FTP client such as lftp, as suggested by @User123, can be much easier.

Hope this helps!

like image 35
Castaglia Avatar answered Oct 25 '25 12:10

Castaglia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!