SFTPClient - 连接错误

时间:2018-01-06 13:03:22

标签: c# ftp sftp ftp-client

使用以下代码

创建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。无法确定问题是在代码中还是在服务器端。

0 个答案:

没有答案