sshnet / sshnet/SSH.NET

Getting "SshConnectionException: Client not connected" on RunCommand despite being inside "if (client.IsConnected)"

Offen
#996 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

Here is my code:

private void connectToMacSSH()
{
    using (var client = new SshClient(sshIp,
                                        22,
                                        sshUsername,
                                        new PrivateKeyFile(rsaKeyFilePath,
                                        sshRsaPrivateKeyPassphrase)))
        {

            client.Connect();

            if (client.IsConnected)
            {
                new Thread(() =>
                {
                    client.RunCommand("caffeinate -u -t 2");
                }).Start();
            }
            else
            {
                ...
            }
        }
    }
}

This is how it's called (in a main method):

sshThread = new Thread(() => { connectToMacSSH(); });
sshThread.Start();

This code was working 100% fine just minutes ago. I have no idea what I changed, but for some reason, even though client.IsConnected returns true, running the client.RunCommand line will throw "SshConnectionException: Client not connected", every time.

The command itself executes fine on another SSH client, using all of the credentials and login details on another SSH client works fine too. I have physical access to the host I am trying to SSH into, it is on (logged in and screen on), connected on the right static local IP, and I can access it via other SSH clients.

I've rewritten the code about 3 times now with no success - I even tried removing the try catch block (around RunCommand) and the command itself from a new thread and running it synchronously instead - it had no effect.

All help widely appreciated, completely unsure of what to try next...

Someone else had this issue... only answer was a dead link https://stackoverflow.com/questions/25522894/client-not-connected-exception-with-ssh-net

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit dem bereitgestellten Einstiegspunkt connectToMacSSH und dem Aufruf RunCommand. Untersuchen Sie anschließend den Lebenszyklus der SSH-Clientverbindung rund um die Thread- und Synchronvarianten. Reproduzieren Sie die gemeldete Ausnahme mit den bereitgestellten Zugangsdaten und dem Befehl und bestimmen Sie, ob es sich um einen Bibliotheksfehler oder um eine problemspezifische Lebenszyklusbedingung handelt, bevor Sie einen Regressionstest oder eine Dokumentationsaktualisierung definieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.