【发布时间】:2015-03-11 10:53:02
【问题描述】:
我正在使用 .NET 4.5,我需要连接到 SFTP 站点并将两个文件下载到我的本地电脑。根据我在互联网上的阅读,我没有可以在 .NET 中使用的内置库。
是否有任何我可以使用的可靠的 3rd 方也有简单的示例?
我有以下
username: myusername
password: mypassword
hostname: fts-sftp.myhost.com
protocol: SFTP
Port: 6621
更新
我有下面的代码,但是我在“sftp.Connect()”行收到以下错误消息。
System.dll 中出现“System.Net.Sockets.SocketException”类型的未处理异常
附加信息:连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应
检查了提供给我的信用证,以确保我没有错字。
using Renci.SshNet;
using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace SftpExample2
{
class Program
{
static void Main(string[] args)
{
string host = "fts-sftp.myaddress.com";
string password = "mypassword";
string username = "myusername";
string remoteDirectory = ".";
int port = 6671;
using (SftpClient sftp = new SftpClient(host, port, username, password))
{
sftp.Connect();
var files = sftp.ListDirectory(remoteDirectory);
foreach (var file in files)
Console.WriteLine(file.FullName);
sftp.Disconnect();
};
}
}
}
【问题讨论】: