public void Connect() { if (IsConnected) { throw new InvalidOperationException("Already connected"); } if (!_userInfoSet) { throw new InvalidOperationException("UserInfo must be set before Connecting"); } _session.connect(); }
public void Open() { try { if (session != null && session.isConnected()) { return; } Tamir.SharpSsh.jsch.JSch jsch = new Tamir.SharpSsh.jsch.JSch(); session = jsch.getSession(tunnel.User, tunnel.RemoteHost, tunnel.Port); session.setHost(tunnel.RemoteHost); session.setPassword(tunnel.Password); Tamir.SharpSsh.jsch.UserInfo ui = new MyUserInfo(); session.setUserInfo(ui); session.connect(); try { //Set port forwarding on the opened session session.setPortForwardingL(3306, "localhost", remotePort); } catch { if (IsOpen()) { Close(); } } if (!session.isConnected()) { throw new DuradosException("Could not open SSH tunnel"); } } catch (Exception exception) { throw new DuradosException("Could not open SSH tunnel", exception); } }