Thanks, it worked. Here's my code :
public void Start()
{
using (var client = new SshClient("vps97919.ovh.net", "tunnel", "123456"))
{
client.KeepAliveInterval = new TimeSpan(0, 0, 30);
client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
client.Connect();
ForwardedPortDynamic port = new ForwardedPortDynamic("127.0.0.1", 1080);
client.AddForwardedPort(port);
port.Exception += delegate(object sender, ExceptionEventArgs e)
{
Console.WriteLine(e.Exception.ToString());
};
port.Start();
System.Threading.Thread.Sleep(1000 * 60 * 8);
port.Stop();
client.Disconnect();
}
this.Start();
}
So I now have two problems :- I have to change the remote address in my VPN config to its IP address otherwise it won't find the remote server
-
As you can see to keep the ssh connexion I use a Thread sleep with a recursive call to itself because my program is running in the background without a console so I can't use readkey. Have any idea of a better practice than that ?