Quantcast
Channel: sshnet Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1026

Created Unassigned: Can not reconnect a portforwarding [2488]

$
0
0
Hello,
I am using Renci Ssh to create a tunnel and get disconnected from time to time.
The problem is that when I try to reconnect I have some trouble :
My code is just some part of the example given :

lock (objectSSHLocker)
{

try
{
if (client_ssh != null)
{
if (client_ssh.IsConnected)
{
client_ssh.Disconnect();
}

client_ssh.Dispose();
}
}
catch (Exception ett)
{
Log.add("Erreur TryToCloseSSHClient: " + ett.Message);
}
try
{
client_ssh = new SshClient(distantSSHServer, distantSSHPortNum, sshloginName, sshpassword);
client_ssh.Connect();
System.Threading.Thread.Sleep(5);
if (client_ssh.IsConnected == false)
{
Log.add("SSH Session NOT connected!!");
}
else
{
Log.add("SSH Session IS connected!!");
}
ForwardedPortLocal tunnel = new ForwardedPortLocal("127.0.0.1", 3333, hostToForwardTo, portToForwardTo);
{
var toDispose = new List<ForwardedPortLocal>();

foreach (ForwardedPortLocal forwardedPort in client_ssh.ForwardedPorts.Where(forwardedPort => forwardedPort.IsStarted))
{
forwardedPort.Stop();
toDispose.Add((ForwardedPortLocal)forwardedPort);
}

foreach (ForwardedPortLocal port in toDispose)
{
client_ssh.RemoveForwardedPort(port);
port.Dispose();
}

}
catch
{ }

client_ssh.AddForwardedPort(tunnel);

tunnel.Exception += delegate(object sender, Renci.SshNet.Common.ExceptionEventArgs eren)
{
Log.add("SSH Tunnel Exception : " + eren.Exception.ToString());
if (eren.Exception.Message == "Session is not connected.")
{
Log.add("2nd Chance");
tunnel.Dispose();
if (isSecondChance == false)
{
isSecondChance = true;
TryToOpenSSHTunnel(distantSSHServer, distantSSHPortNum, sshloginName, sshpassword, localPort, hostToForwardTo, portToForwardTo);
}
}
};

tunnel.Start();

return true;
}
catch (Exception ex)
{
Log.add("Error connect SSH : " + ex.Message);
if (Properties.Settings.Default.UseDBGMSG == true)
MessageBox.Show("Error connect SSH : " + ex.Message);
return false;
}
}
}

Do you have any idea?
Is it a delay issue?

Viewing all articles
Browse latest Browse all 1026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>