Click here to Skip to main content
15,943,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm writing a java code to transfer and delete remote files using FTP. Basically i'm sending the raw FTP commands (like "DELE") for the transfer/deletion of files. For e.g

sendLine("DELE " + filename);

private void sendLine(String line) throws IOException {
  if (socket == null) {
    throw new IOException("FTP is not connected.");
  try {
    writer.write(line + "\r\n");
    if (DEBUG) {
      System.out.println("> " + line);
  } catch (IOException e) {
    socket = null;
    throw e;

Now i would like to delete an entire folder. Can someone tell me how i can remove an entire (non-empty) folder? Are there any raw FTP commands to do so? Am quite desperate!

1 solution

The joyful world of FTP-Commands[^]

The command for deleting a folder (better known as directory) is "rmdir".
You might have to check for the rights - but that's similar handled as on the files.
Share this answer
S.Raaj Nishanth 6-Dec-11 23:11pm    
Yup....that was the first thing that came up when i "googled" the problem...however 'rmdir' is not a RAW FTP command so one cannot send it through java code (i think). I tried sending a site command (SITE RMDIR) but that didn't work either. Besides, the folder that i want to delete may have subfolders as well. I want everything to be deleted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900