'No such file' 使用 Tamir.SharpSSH 通过 sftp 下载文件
'No such file' using Tamir.SharpSSH to download file via sftp
我在 sftp.GetFileList(ftp主机)上收到错误消息 "No such file"。
使用我测试过的给定 ip 和凭据,他们有权访问我正在连接的所有目录。
string FileName = Label6.Text;
string rootPath = Server.MapPath("~");
string FolderName = "\DL" + DateTime.Now.ToString("yyyyMMddHHmmss");
System.IO.Directory.CreateDirectory(rootPath + FolderName);
string rootPath1 = rootPath + FolderName;
string ftphost = "***.***.***.***";
string ftpfullpath = "ftp://" + ftphost + FileName;
int port = 22;
Sftp sftp = new Sftp("***.***.***.***", "@!#^@!^$", "!@#^#@#^&");
sftp.Connect(port);
sftp.GetFileList(ftphost);
ArrayList res = sftp.GetFileList(ftphost);
foreach (var item in res)
{
if (item.ToString() != "." && item.ToString() != "..")
Debug.WriteLine(item.ToString());
}
sftp.Get(ftpfullpath, rootPath1);
编辑:另外,用于连接 ftp 的帐户上有一个脚本,可以将其放入特定目录,是否有必要以某种方式将 Get 或 GetFileList 重定向到根目录?
GetFileList
方法接受检索列表的路径。不是主机名。您已经在 Sftp
构造函数中指定了主机名。
Get
方法相同。
- 另外,你用的是SFTP协议,为什么要加
ftp://
前缀?
- 请注意,您调用了
GetFileList
两次。
- SharpSSH 是一个糟糕的选择。它没有维护多年。
我在 sftp.GetFileList(ftp主机)上收到错误消息 "No such file"。 使用我测试过的给定 ip 和凭据,他们有权访问我正在连接的所有目录。
string FileName = Label6.Text;
string rootPath = Server.MapPath("~");
string FolderName = "\DL" + DateTime.Now.ToString("yyyyMMddHHmmss");
System.IO.Directory.CreateDirectory(rootPath + FolderName);
string rootPath1 = rootPath + FolderName;
string ftphost = "***.***.***.***";
string ftpfullpath = "ftp://" + ftphost + FileName;
int port = 22;
Sftp sftp = new Sftp("***.***.***.***", "@!#^@!^$", "!@#^#@#^&");
sftp.Connect(port);
sftp.GetFileList(ftphost);
ArrayList res = sftp.GetFileList(ftphost);
foreach (var item in res)
{
if (item.ToString() != "." && item.ToString() != "..")
Debug.WriteLine(item.ToString());
}
sftp.Get(ftpfullpath, rootPath1);
编辑:另外,用于连接 ftp 的帐户上有一个脚本,可以将其放入特定目录,是否有必要以某种方式将 Get 或 GetFileList 重定向到根目录?
GetFileList
方法接受检索列表的路径。不是主机名。您已经在Sftp
构造函数中指定了主机名。Get
方法相同。- 另外,你用的是SFTP协议,为什么要加
ftp://
前缀? - 请注意,您调用了
GetFileList
两次。 - SharpSSH 是一个糟糕的选择。它没有维护多年。