【问题标题】:"SocketException: Could not resolve host" when connecting to SFTP server with SSH.NET使用 SSH.NET 连接到 SFTP 服务器时出现“SocketException:无法解析主机”
【发布时间】:2019-01-09 01:32:28
【问题描述】:

尝试将文件上传到我本地的 SFTP 服务器。连接 SFTP 时遇到错误。

System.Net.Sockets.SocketException: 无法解析主机 'sftp://localhost'

我尝试使用命令行和 FileZilla 进行连接。可以连接。

string host = "sftp://localhost";
int port = 22;
string username = "gth";
string password = "1234";
using (SftpClient client = new SftpClient(host, port, username, password))
{
    client.Connect();
}

它在下面显示错误:

Loaded assembly: System.Threading.Tasks.dll [External] 
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
Thread started: <Thread Pool> #6
Thread started: <Thread Pool> #7
Unhandled Exception:
01-09 11:47:25.081 E/mono    (12159): 
01-09 11:47:25.081 E/mono    (12159): Unhandled Exception:
01-09 11:47:25.081 E/mono    (12159): System.Net.Sockets.SocketException (0x80004005): Connection refused
01-09 11:47:25.081 E/mono    (12159):   at (wrapper dynamic-method) System.Object.5(intptr,intptr,intptr)
01-09 11:47:25.081 E/mono-rt (12159): [ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException (0x80004005): Connection refused
01-09 11:47:25.081 E/mono-rt (12159):   at (wrapper dynamic-method) System.Object.5(intptr,intptr,intptr)
01-09 11:47:25.099 E/CameraBase(12159): SCANNING dlclose for instance 0x437bbb5ee79d6b9f
01-09 11:47:25.100 E/CameraBase(12159): SCANNING AFTER DLCLOSE

【问题讨论】:

    标签: c# .net xamarin.android sftp ssh.net


    【解决方案1】:

    SftpClient 构造函数的host 参数采用主机名称,而不是 URL。

    所以只需删除sftp://

    host = "localhost";
    

    【讨论】:

      【解决方案2】:

      或使用 127.0.0.1 代替 localhost

      【讨论】:

        猜你喜欢
        • 2022-06-14
        • 1970-01-01
        • 1970-01-01
        • 2019-10-24
        • 1970-01-01
        • 2020-09-16
        • 1970-01-01
        • 1970-01-01
        • 2019-05-20
        相关资源
        最近更新 更多