1

In my FTP Client application in MFC VC++, I am listing a server's directory files and deleting them successfully. LIST and NLIST commands work fine in listing the directory files/content.

As well as the files, two folders (which contain files which are not listed) appear on the list which is correct. However, when I pass DELE command to these folders, an error is returned and the folders remain. I feel that this is because they are folders.

Below is the Delete() function I have implemented:

int CFTPClient::Delete(const tstring& strFile) const
{
   ASSERT( !strFile.empty() );
   CReply Reply;
   if( !SendCommand(CCommand::DELE(), strFile, Reply) )
       return FTP_ERROR;
   return SimpleErrorCheck(Reply);
}

My question is this: Are there any commands in FTP which remove/delete folders? I am referring to the RFC 959 FTP protocol. DELE and RMD commands do not work for folders.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
MDK
  • 57
  • 1
  • 8
  • why does `RMD` not work? "This command causes the directory specified in the pathname to be removed as a directory" – m.s. Sep 03 '15 at 08:18
  • *"an error is returned"* - which error? Anyway, try DELE on the folders' files first, then RMD on the folders themselves. – Tony Delroy Sep 03 '15 at 08:27
  • When using RMD and DELE, "521 Error removing directory" and "521 Error deleting file" appear on WireShark... NLIST lists the directory files and folders, but the folder contents I can't access ... any ideas how I can access or 'open' the folders somehow? – MDK Sep 03 '15 at 08:37

1 Answers1

2

The RMD command can in general remove an empty directory only.

So first, you have to recursively delete the directory contents before issuing the RMD command.

See also FTP Protocol and Deleting Directories.

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Yes I am recursively deleting all files in the directory which works fine. However, the two folders are not deleted as DELE does not remove them. – MDK Sep 03 '15 at 09:27
  • You have to use `RMD`, not `DELE` on directories. Can you delete the folders using a GUI FTP client? – Martin Prikryl Sep 03 '15 at 09:40
  • I've been using SmartFTP Client but it does not offer the option to delete directory content...do you know any commands which list folder content/files in a directory? – MDK Sep 03 '15 at 10:24
  • I cannot try now, but I doubt SmartFTP cannot delete directory recursively. Can you try WinSCP or another FTP client and show us its log? To list directory contents, use `NLST`. – Martin Prikryl Sep 03 '15 at 11:12
  • Yes WinSCP uses LIST to list the directory("\") content and CWD to open the folder or change directory in other words(i.e. CWD \IMAGES). However, when I tried to delete files in the images folder, the same 521 error was thrown in WireShark. DELE does not work either. Very frustrating. Thanks for the help. – MDK Sep 03 '15 at 11:50
  • What happens if you create a fresh new folder and try to delete it? – Martin Prikryl Sep 03 '15 at 11:51
  • What is your FTP server? – Martin Prikryl Sep 03 '15 at 11:52
  • I'll try that now.. my server happens to be a company firmware module that I'm a uploading files to via it's static IP... – MDK Sep 03 '15 at 12:51