使用 Chilkat 从 SFTP 目录中删除所有内容

Deleting all contents from SFTP directory using Chilkat

我一直在使用 Chilkat SFTP,它非常适合我需要它做的事情。但是,我在尝试从远程服务器中删除目录时遇到了一个问题。

目前,它说要删除一个目录是空的,所以我不得不结合使用模式99的syncTreeDownload方法,并将其同步到我本地机器上的一个空目录。

这并不是一个理想的解决方案,因为它将被部署,因此我将无法找到一个空目录来在客户端机器上同步。递归循环删除所有内容然后删除目录的目录也非常困难。

有没有人以前遇到过这种情况并且有解决这个问题的轻量级解决方案?必须有一个简单的方法来实现这一点。

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

难怎么办?为了发展?还是因为时间长? SFTP 协议没有其他方法。


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.

您可以在 %TEMP% (Path.GetTempPath) 中创建一个新的临时子文件夹。


如果您有 shell 访问权限(除了 SFTP),您可以在服务器上执行 rm -rf shell 命令(或等效命令,如果您没有连接到*nix 服务器)——例如使用 Ssh.QuickCommand 方法。这是一个快速简单(但也很脏)的解决方案。