【发布时间】:2015-03-09 07:37:37
【问题描述】:
我需要通过 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]);
}
}
}
有效,但似乎不正确。
【问题讨论】:
-
您的代码似乎发生了任何异常,然后您尝试递归但不清楚要递归的位置..
-
不知道这是什么意思:
It works, but it seems not correct. -
@Dan-o 我很确定这意味着 OP 正在尝试编写健壮的代码,而不是“恰好工作”的代码。对常规程序流使用异常是很臭的。