Esempio n. 1
0
 public bool OpenConnection(RemoteSystem _defaultGateway, int _localPort)
 {
     if (!this.IsConnected ()) {
         var jsch = new JSch ();
         var gw = _defaultGateway;
         this.LPort = _localPort;
         this.SSHSession = jsch.getSession (gw.GetUser (), gw.GetHost (), gw.GetPortNumber ());
         this.SSHSession.setUserInfo (new RemoteUserInfo (gw));
         try {
             this.SSHSession.connect ();
         } catch (Tamir.SharpSsh.jsch.JSchException ex) {
             Console.WriteLine ("Could not establish connection to remote gateway.");
             return false;
         }
         if (this.IsConnected ()) {
             this.SSHSession.setPortForwardingL (this.LPort, this.GetHost (), this.GetPortNumber ());
             this.RemoteSession = new RemoteConnection (this);
             this.RemoteSession.ConnectionClosed += (object sender, ConnectionEventArgs args) => { this.CloseConnection (); };
             this.RemoteSession.Open ();
         }
     }
     return this.IsConnected ();
 }
Esempio n. 2
0
 public bool CloseConnection()
 {
     if (this.IsConnected ()) {
         this.RemoteSession.Close ();
         this.RemoteSession = null;
         this.SSHSession.delPortForwardingL (this.LPort);
         this.SSHSession.disconnect ();
         this.OnConnectionClosed (this, new ConnectionEventArgs (this, "closed"));
         this.SSHSession = null;
     }
     return !this.IsConnected ();
 }