c# - Renci SSH.net 更改远程 SFTP 端口请求 C#
问题描述
我正在用 C#(VS 2017)编写一小段代码,通过 SOCKS 代理使用 SFTP 将文件上传到远程服务器。
我之前曾将 Renci SSH.net 用于与此类似的其他应用程序,完全没有问题。
然而,在这个应用程序中,我遇到了一个问题,即 Renci SSH.net 对 Socks 代理的调用是针对与我请求的端口不同的端口。
这是我的代码
private static void testSFTPConnection()
{
//get the SFTP Connection Info
ConnectionInfo connInfo = testRemoteSFTP();
try
{
//Start the SFTP Client
using (SftpClient remoteSFTPClient = new SftpClient(connInfo))
{
//Connect the remote session
remoteSFTPClient.Connect();
//log a successful connection
Console.WriteLine("SFTP File Upload - connection to the file destination server successful");
//Disconnect the Destination SFTP connection
remoteSFTPClient.Disconnect();
}
}
catch(Exception ex)
{
Console.WriteLine("SFTP File Upload Exception: " + ex.Message);
}
}
public static ConnectionInfo testRemoteSFTP()
{
return new ConnectionInfo(remoteHost,50101, remoteUser,ProxyTypes.Socks5, proxyURL,proxyPort, proxyUser, proxyPwd, new PasswordAuthenticationMethod(remoteUser,remotePwd));
}
如您所见,我正在设置连接信息以在端口 50101 上调用远程主机(根据他们的请求)但是当我运行代码时,SOCKS 代理告诉我我正在请求连接到端口 50297 上的远程服务器。
当我尝试在 VS 2017 中调试连接信息时,连接对象向我显示端口请求为 50101,但它仍然命中代理请求端口 50297
我使用 WinSCP 测试了通过端口 50101 上的 SOCKS 代理与远程服务器的连接,并且连接正常。
我使用 Wire Shark 尝试捕获我的传出连接请求,我可以看到端口请求已更改为 50297
我现在不知道这可能是什么原因或应用什么修复,所以在这方面的任何帮助将不胜感激
提前致谢
解决方案
推荐阅读
- php - PHP通过另一个数组的值隔离数据
- javascript - how to send data from webpage to mobile device via SMS
- ios - Draw text on Bezier path
- asp.net-mvc - MVC 中 RedirectToAction 的 ModelState 验证
- ms-access - Access 为我带来所选列中的随机记录
- android - How to automatically update mobile app (from Managed Google Play) with Microsoft Intune
- java - Multiple Inheritance using Anonymous class in Java
- javascript - 开发 Office 加载项时“‘应用程序’未定义”
- r - 在 R 中抓取数据
- rest - ArcGIS REST API - 如何查看 geoJSON 结果?