繁体   English   中英

使用 SFTP 客户端库 SSH.NET 的连接尝试失败

[英]A Connection Attempt Failed using the SFTP Client library SSH.NET

使用 SSH.NET 库创建 SFTP 客户端代码以使用以下代码传输文本文件:

string destinationWithFileName = string.Format("{0}/{1}", "test/transferredfiles/", DateTime.Now.Ticks + "hello.txt");
SftpClient _sftpClient = new SftpClient("sftp.example.com", 22, "username", "password");
if (!_sftpClient.IsConnected)
{
    _sftpClient.Connect();
    byte[] fileContent = File.ReadAllBytes(@"C:\helloworld.txt");
    Stream stream = new MemoryStream(fileContent);
    _sftpClient.UploadFile(stream, destinationWithFileName);
    _sftpClient.Disconnect();
}

但是在尝试连接时出现以下异常 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 无法确定问题是在代码中还是在服务器端。

  • 在没有 FTP 限制的防火墙的另一台机器上尝试代码。

  • 下载一个 FTP 客户端(Filezilla、WinScp),看看是否遇到同样的问题。

就我而言,公司政策阻止我的本地计算机建立 FTP 连接。 当我在开发服务器上编译并运行这段代码时,它连接没有错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM