1

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
srozzar
  • 15
  • 1
  • 6
  • 1
    Could you make an empty folder for the purpose? [Creating temporary folders](https://stackoverflow.com/q/16656/1115360). – Andrew Morton Jan 13 '20 at 10:26
  • 1
    thanks @AndrewMorton, have implemented that! completely forgot that was possible... its monday morning after all! – srozzar Jan 13 '20 at 10:40

1 Answers1

1

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • That was my initial thought, if i was on a terminal i could just remove the directory recursively so i thought maybe there was a similar operation within the library. thanks for the temp idea, what i needed, thanks..! guess i will try and improve my recursive loop ability...! – srozzar Jan 13 '20 at 10:39
  • I mean that you can execute the `rm` shell command *using the library*. E.g. using the `QuickCommand` method. -- Though recursive code using SFTP would be a more robust (while more complicated and slower) solution. – Martin Prikryl Jan 13 '20 at 10:53
  • i guess thats what i have to weigh up! will have a play and see which one is better for what i need, again, thanks for your input, appreciate it! – srozzar Jan 13 '20 at 10:56