"SocketException:无法解析主机"使用SSH.NET连接到SFTP服务器时 [英] "SocketException: Could not resolve host" when connecting to SFTP server with SSH.NET

查看:248
本文介绍了"SocketException:无法解析主机"使用SSH.NET连接到SFTP服务器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将文件上传到本地的SFTP服务器.连接SFTP时发生错误.

Trying to upload file to SFTP server in my local. Hit error when connect SFTP.

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

System.Net.Sockets.SocketException: Could not resolve host 'sftp://localhost'

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

I've tried using command-line and FileZilla to connect. It can connected.

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

它在下面显示了我的错误:

It show me error below:

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

推荐答案

host自变量/SftpClient/ctor"rel =" nofollow noreferrer> SftpClient构造函数使用主机名称,而不是URL.

The host argument of SftpClient constructor takes hostname, not URL.

所以只需放下sftp://:

host = "localhost";

这篇关于"SocketException:无法解析主机"使用SSH.NET连接到SFTP服务器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆