我需要通过 SharpSsh 将文件从服务器递归下载到 SFTP。但我不明白如何确定文件名或目录。现在我这样做
static void recDir(string remotePath, string localPath)
{
Sftp _c = this.sftp;
ArrayList FileList = _c.GetFileList(remotePath);
FileList.Remove(".");
FileList.Remove("..");
for (int i = 0; i < FileList.Count; i++)
{
try
{
_c.Get(remotePath + "/" + FileList[i], localPath + "/" + FileList[i]);
Console.WriteLine("File: " + remotePath + "/" + FileList[i]);
}
catch (Exception e)
{
Console.WriteLine("Dir: " + remotePath + "/" + FileList[i]);
System.IO.Directory.CreateDirectory(localPath + "/" + FileList[i]);
recDir(remotePath + "/" + FileList[i], localPath + "/" + FileList[i]);
}
}
}
它有效,但似乎不正确。