Search code examples
.netvb.netsftpchilkat

Deleting all contents from SFTP directory using Chilkat


I have been using Chilkat SFTP, which has been great for what I need it to do. However, I have came across a problem when trying to remove directories from the remote server.

At present, it says that a directory is to be empty to be removed, so I have had to incorporate the syncTreeDownload method utilising mode 99, and sync it to an empty directory on my local machine.

This is'nt really an ideal solution as it will be getting deployed and thus I won't be able to find an empty directory to sync on clients machines. It is also extremely difficult to recursively loop down the directories removing all contents and then removing the directory.

Has anybody came across this situation previously and have a lightweight solution to solving this? There must be a simple way to achieve this.


Solution

  • It is also extremely difficult to recursively loop down the directories removing all contents and then removing the directory.

    Difficult how? For development? Or because it takes long? There's no other way with SFTP protocol.


    This isn't really an ideal solution as it will be getting deployed and thus I won't be able to find an empty directory to sync on clients machines.

    You can create a new temporary subfolder in %TEMP% (Path.GetTempPath).


    If you have a shell access (in addition to SFTP), you can execute rm -rf shell command on the server (or an equivalent, if you are not connecting to a *nix server) – e.g. using Ssh.QuickCommand method. It is a quick and easy (and dirty) solution.