Getting "SshConnectionException: Client not connected" on RunCommand despite being inside "if (client.IsConnected)"
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 4.4k
- Fork
- 993
- Merge medio
- 9g 21h
- PR unite (30g)
- 1
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Iniziare dal punto di ingresso connectToMacSSH fornito e dalla chiamata RunCommand, quindi esaminare il ciclo di vita della connessione del client SSH intorno alle varianti con thread e sincrona. Riprodurre l'eccezione segnalata usando le credenziali e il comando forniti e determinare se il comportamento è dovuto a un difetto della libreria o a una condizione del ciclo di vita specifica del problema prima di definire un test di regressione o un aggiornamento della documentazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100