This project is read-only.

Unable to connect in WinForms

Mar 12, 2012 at 4:27 PM
Edited Mar 12, 2012 at 4:30 PM

Hello. I am new to SSH so if I am doing something blatantly obvious, then I am sorry in advance. So I have two applications: 1) Console app that connects, reads/parses data sent over SSH wire and does Console.WriteLine of what I parsed. That works awesome, no problems. 2) WinForms application that connects the exact same way but shows the parsed data visually. 


That being said, I am not able to connect using the WinForms application. I keep getting these exceptions: 




The exception message says: 

An established connection was aborted by the software in your host machine.


Here is a copy paste (I changed the connect IP though :) )


this.sshClient = new SshClient("888.888.888.888", "user", new PrivateKeyFile(new MemoryStream(Resources.rsa)));
this.sshClient.ErrorOccurred += (sender, e) => { Log(string.Format("Failed!! {0}", e.Exception.Message)); };
this.sshClient.HostKeyReceived += (sender, e) => { Log(string.Format("Host key is received!")); };

AddForwardedPort(this.sshClient, "", 22000, "localhost", 80);
AddForwardedPort(this.sshClient, "", 22001, "localhost", 12001);
AddForwardedPort(this.sshClient, "", 22002, "localhost", 12002);
AddForwardedPort(this.sshClient, "", 22003, "localhost", 11026);
AddForwardedPort(this.sshClient, "", 22004, "localhost", 12106);


The .Connect() just sits there and then eventually times out. Any thoughts as to why it works just fine with my Console app, but not in WinForms? I am using the Release version of your latest code (March 9th, 2012 version). If you need more information then let me know and I can get that to you.

Mar 13, 2012 at 4:09 PM

Top... Sorry I am at a loss on this and was hoping to get some guidance.

Mar 13, 2012 at 4:12 PM



Sorry for not replying since I I have no idea what might be the problem there :(.


My only guess would be it has something to do with threads, so may be make sure you not running it on UI thread but may be on dedicate background thread.



Mar 13, 2012 at 4:15 PM

Ok thanks. I will try that and report back. I dont know which thread I am doing it on currently.

Mar 13, 2012 at 4:19 PM

You are a genius. Works awesome now.