Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法连接到C#-Renci.SshNet错误中的SshClient_C#_Ssh_.net 4.0_Ipv6 - Fatal编程技术网

无法连接到C#-Renci.SshNet错误中的SshClient

无法连接到C#-Renci.SshNet错误中的SshClient,c#,ssh,.net-4.0,ipv6,C#,Ssh,.net 4.0,Ipv6,我在C#中工作,试图使用Renci.SshNet创建连接,以便在网络上的设备上运行SSH命令。在程序的早期,一切都很正常,但是当我尝试创建连接并连接它时,会出错,而try-catch会显示此错误消息 System.Net.Sockets.SocketException(0x80004005):连接尝试 失败,因为关联方在发生错误后没有正确响应 一段时间,或由于已连接而建立的连接失败 主机未能响应 位于Renci.SshNet.Abstractions.SocketAbstraction.Conn

我在C#中工作,试图使用Renci.SshNet创建连接,以便在网络上的设备上运行SSH命令。在程序的早期,一切都很正常,但是当我尝试创建连接并连接它时,会出错,而try-catch会显示此错误消息

System.Net.Sockets.SocketException(0x80004005):连接尝试 失败,因为关联方在发生错误后没有正确响应 一段时间,或由于已连接而建立的连接失败 主机未能响应
位于Renci.SshNet.Abstractions.SocketAbstraction.Connect(IPEndPoint remoteEndpoint,TimeSpan连接超时)
在Renci.SshNet.Session.SocketConnect(字符串主机,Int32端口)
位于Renci.SshNet.Session.Connect()的Renci.SshNet.BaseClient.Connect()
在D:\Devices\Juniper-CTP\Driver Code C\

尝试进一步修复后更新。

引发的另一个错误消息是:

System.Net.Sockets.SocketException(0x80004005):请求的地址在其上下文中无效
位于Renci.SshNet.Abstractions.SocketAbstraction.Connect(IPEndPoint remoteEndpoint,TimeSpan connectTimeout)
在Renci.SshNet.Session.SocketConnect(字符串主机,Int32端口)
在Renci.SshNet.Session.Connect()上 位于Renci.SshNet.BaseClient.Connect()
在SAS.JuniperCTPDriver.tuneJuniper(字符串destp、Int32 destBundle、字符串destName、, 字符串设备、字符串srcIP、Int32 srcBundle、字符串srcName、字符串srcInfo、字符串srcCircIDs、, 字符串destCircIDs、字符串newBundles、Int32 srcOldBndl、Int32 destOldBndl) 在D:\Devices\Juniper-CTP\Driver Code C\#\JuniperCTPDriver.cs中:第1074行

如果有人对这个问题有任何见解,我们将不胜感激

string srcIP = "FD52:A651:105:40::503";
string destIP = "an IPv6 address like the first";
int srcBundle = 1;
int destBundle = 3;
int rSrcCircID = -1;
string srcName = "se-0/0";
string destName = "se-0/1";
//make sure that any already set up connections are removed
if (rSrcCircID <= -1) {
    bool res = RemoveBundle(srcIP, srcBundle);
    if (!res) {
        Console.WriteLine("was not able to remove old connection");
    }                
}


//create the bundles if they do not exist yet
if (newSrcBndl == "y")
{
    CreateBundle(srcIP, srcBundle, srcName);
}

if (newDestBndl == "y")
{
    CreateBundle(destIP, destBundle, destName);
}


using (var destClient = new SshClient(destIP, "usrname", "pw"))
{

    destClient.Connect(); //THIS IS LINE 1074

    //set bundle direction for the destination
    result = ExecuteSSHCommand(destClient, "cmd bndl " + destBundle + " cfg flags simplex_dst");
    if (result == "false")
    {
        LogMsg(3, "-- destination direction flag set failed.");
        return "failed3";
    }

.
.
.

    destClient.Disconnect();
}
所有SSH命令发送到的另一个函数如下

private static string ExecuteSSHCommand(SshClient s, string scmd) {
    try {
        var command = string.Format(scmd);
        var cmd = s.CreateCommand(command);
        var result = cmd.Execute();

        return result;
    } catch {
        return "false";
    }
}

我到处寻找有同样问题的人,但不是没有一个答案是有用的,就是他们不是同一个问题。如果您有这样做的专业知识,请提供帮助。

此错误表示防火墙挡住了您的去路。您是否验证了您可以在指定的端口上访问服务器?使用putty或telnet查看端口22是否打开。@fredrik您可能在正确的轨道上,但我无法验证它是否在网络上。即使在打开一个新的SSH连接之前我非常努力地关闭了一个SSH连接,我仍然有这个问题。@Jawad我用putty连接到了设备,一切都正常工作。
private static string ExecuteSSHCommand(SshClient s, string scmd) {
    try {
        var command = string.Format(scmd);
        var cmd = s.CreateCommand(command);
        var result = cmd.Execute();

        return result;
    } catch {
        return "false";
    }
}