sftpsharpsshrmdir

How could I use rmdir in SFTP to remove remote folders not empty?


Recently, I'm using SharpSSH to deal with remote files. The SharpSSH offers API of rmdir for removing remote directories, but I find that it throws exceptions with message "Permission denied" when the directory is not empty. Then I've got to delete each file before the final rmdir recursively, which is not efficient.

So how could I use this rmdir without the fool recursive deletion?


Solution

  • You cannot. In SFTP protocol, in general, there's no API to delete a folder recursively.

    So even if you use another library that allows deleting a folder with a single call (like my WinSCP Session.RemoveFiles), it still internally has to recurse into subdirectories.


    Side note: Do not use SharpSSH, it's a dead project.