Exemple #1
0
 public override void start()
 {
     try
     {
         Request request;
         if (xforwading)
         {
             request = new RequestX11();
             request.request(session, this);
         }
         if (pty)
         {
             request = new RequestPtyReq();
             request.request(session, this);
         }
         request = new RequestShell();
         request.request(session, this);
     }
     catch //(System.Exception e)
     {
         throw new JSchException("ChannelShell");
     }
     thread = new JavaThread(this);
     thread.Name("Shell for " + session.host);
     thread.Start();
 }
Exemple #2
0
        public override void start()
        {
            try
            {
                Request request;

                if (xforwading)
                {
                    request = new RequestX11();
                    request.request(session, this);
                }

                if (pty)
                {
                    request = new RequestPtyReq();
                    request.request(session, this);
                }

                request = new RequestExec(command);
                request.request(session, this);
            }
            catch (Exception)
            {
                throw new JSchException("ChannelExec");
            }
            thread = new JavaThread(this);
            thread.Name("Exec thread " + session.getHost());
            thread.Start();
        }
Exemple #3
0
        public virtual void disconnect()
        {
            //System.Out.println(this+":disconnect "+io+" "+io.in);
            if (!connected)
            {
                return;
            }
            connected = false;

            close();

            _eof_remote = eof_local = true;

            thread = null;

            try
            {
                if (io != null)
                {
                    io.close();
                }
            }
            catch (Exception)
            {
                //e.printStackTrace();
            }
            io = null;
            del(this);
        }
Exemple #4
0
        public override void start()
        {
            try
            {
                Request request;
                if (xforwading)
                {
                    request = new RequestX11();
                    request.request(session, this);
                }
                if (pty)
                {
                    request = new RequestPtyReq();
                    request.request(session, this);
                }
                request = new RequestSubsystem();
                ((RequestSubsystem)request).request(session, this, subsystem, want_reply);
            }
            catch (Exception e)
            {
                if (e is JSchException)
                {
                    throw (JSchException)e;
                }
                throw new JSchException("ChannelSubsystem");
            }
            JavaThread thread = new JavaThread(this);

            thread.Name("Subsystem for " + session.host);
            thread.Start();
        }
Exemple #5
0
        public override void run()
        {
            thread = new JavaThread(Thread.CurrentThread);
            Buffer buf    = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int    i      = 0;

            try
            {
                while (thread != null && io != null && io.ins != null)
                {
                    i = io.ins.Read(buf.buffer,
                                    14,
                                    buf.buffer.Length - 14
                                    - 32 - 20 // padding and mac
                                    );
                    if (i <= 0)
                    {
                        eof();
                        break;
                    }
                    packet.reset();
                    if (_close)
                    {
                        break;
                    }
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    session.write(packet, this, i);
                }
            }
            catch (Exception)
            {
                //System.out.println(e);
            }

            //thread=null;
            //eof();
            disconnect();
        }
Exemple #6
0
        public override void connect()
        {
            try
            {
                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((byte)90);
                buf.putString(Util.getBytes("direct-tcpip"));
                buf.putInt(id);
                buf.putInt(lwsize);
                buf.putInt(lmpsize);
                buf.putString(Util.getBytes(host));
                buf.putInt(port);
                buf.putString(Util.getBytes(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);
                        Thread.Sleep(50);
                        retry--;
                    }
                }
                catch
                {
                }

                if (!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                if (retry == 0 || this._eof_remote)
                {
                    throw new JSchException("channel is not opened.");
                }

                /*
                 *              if(this.eof_remote){      // failed to open
                 *                disconnect();
                 *                return;
                 *              }
                 */

                connected = true;

                thread = new JavaThread(this);
                thread.Start();
            }
            catch (Exception e)
            {
                io.close();
                io = null;
                del(this);
                if (e is JSchException)
                {
                    throw (JSchException)e;
                }
            }
        }