试图将文件上传到本地的SFTP服务器。连接SFTP时命中错误。
Ftp://localhost‘:无法解析主机的System.Net.Sockets.SocketException
我试过使用命令行和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发布于 2019-01-09 07:15:17
host构造函数的SftpClient参数采用主机名称,而不是URL。
所以只要放下sftp://
host = "localhost";发布于 2020-11-07 08:06:14
或者使用127.0.0.1代替本地主机
https://stackoverflow.com/questions/54102112
复制相似问题