Ubuntu – delete files from FTP servers with linux terminal

command lineftpserver

I'm new here, I would like to ask a question about FTP.

I have an FTP server that contains multiple folders and there are PDF files in them. I wonder if there is a way to access this server through the terminal and delete PDF files through the terminal.

my OS is ubuntu 19.10

I use this command to download the folders

wget -m --user=XXXXX --password=XXXX ftp://XXXXXXX:XXXX/

Now I just need a command to be able to delete the PDF files from the server. šŸ™‚

Best Answer

To delete files/folders from an FTP server, follow these steps:

  1. Type ftp and enter to continue.
  2. Type open and enter to continue.
  3. Type the ftp server IP address and enter to connect to ftp server.
  4. If connected, type login name and enter.
  5. Type user password and enter. If the username and password are valid, then you'll be in.
  6. Type help to list all available commands that you can run on an ftp server.
  7. Type ls to list all files and directories.
  8. Type cd <folder_name> to get into a specified folder.
  9. type mdelete <filename> to delete a file or multiple files or rmdir -r <folder_name> to delete a folder.
  10. Type y and enter to confirm the delete.

EDIT:
For some security reasons, you have to type y everytime you want to delete a file. To avoid that, you need to run ftp -i in the beginning (instead of ftp). After that, you can delete files directly without typing y for every file (exp: mdelete folder_name/* will delete all files in folder_name).
Also, you can not delete a folder unless it is empty, so you have to delete all its content using mdelete folder_name/*, then run rmdir folder_name to delete a folder.

Credits: Mass delete files in FTP server

Related Question