Esempio n. 1
0
 public virtual void Disconnect()
 {
     //System.err.println(this+":disconnect "+io+" "+connected);
     //Thread.dumpStack();
     try
     {
         lock (this)
         {
             if (!connected)
             {
                 return;
             }
             connected = false;
         }
         Close();
         eof_remote = eof_local = true;
         thread     = null;
         try
         {
             if (io != null)
             {
                 io.Close();
             }
         }
         catch (Exception)
         {
         }
     }
     finally
     {
         //e.printStackTrace();
         // io=null;
         Channel.Del(this);
     }
 }
 /// <exception cref="NSch.JSchException"></exception>
 public override void Connect()
 {
     try
     {
         Session _session = GetSession();
         if (!_session.IsConnected())
         {
             throw new JSchException("session is down");
         }
         if (io.@in != null)
         {
             thread = new Sharpen.Thread(this);
             thread.SetName("DirectTCPIP thread " + _session.GetHost());
             if (_session.daemon_thread)
             {
                 thread.SetDaemon(_session.daemon_thread);
             }
             thread.Start();
         }
     }
     catch (Exception e)
     {
         io.Close();
         io = null;
         Channel.Del(this);
         if (e is JSchException)
         {
             throw (JSchException)e;
         }
     }
 }
Esempio n. 3
0
 /// <exception cref="NSch.JSchException"></exception>
 public override void Connect()
 {
     try
     {
         Session _session = GetSession();
         if (!_session.IsConnected())
         {
             throw new JSchException("session is down");
         }
         Buffer buf    = new Buffer(150);
         Packet packet = new Packet(buf);
         // send
         // byte   SSH_MSG_CHANNEL_OPEN(90)
         // string channel type         //
         // uint32 sender channel       // 0
         // uint32 initial window size  // 0x100000(65536)
         // uint32 maxmum packet size   // 0x4000(16384)
         packet.Reset();
         buf.PutByte(unchecked ((byte)90));
         buf.PutString(Util.Str2byte("direct-tcpip"));
         buf.PutInt(id);
         buf.PutInt(lwsize);
         buf.PutInt(lmpsize);
         buf.PutString(Util.Str2byte(host));
         buf.PutInt(port);
         buf.PutString(Util.Str2byte(originator_IP_address));
         buf.PutInt(originator_port);
         _session.Write(packet);
         int retry = 1000;
         try
         {
             while (this.GetRecipient() == -1 && _session.IsConnected() && retry > 0 && !eof_remote
                    )
             {
                 //Thread.sleep(500);
                 Sharpen.Thread.Sleep(50);
                 retry--;
             }
         }
         catch (Exception)
         {
         }
         if (!_session.IsConnected())
         {
             throw new JSchException("session is down");
         }
         if (retry == 0 || this.eof_remote)
         {
             throw new JSchException("channel is not opened.");
         }
         connected = true;
         if (io.@in != null)
         {
             thread = new Sharpen.Thread(this);
             thread.SetName("DirectTCPIP thread " + _session.GetHost());
             if (_session.daemon_thread)
             {
                 thread.SetDaemon(_session.daemon_thread);
             }
             thread.Start();
         }
     }
     catch (Exception e)
     {
         io.Close();
         io = null;
         Channel.Del(this);
         if (e is JSchException)
         {
             throw (JSchException)e;
         }
     }
 }