Ejemplo n.º 1
0
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            bool reply=waitForReply();
            if(reply)
            {
                channel.reply=-1;
            }

            packet.reset();
            buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.putInt(channel.getRecipient());
            buf.putString(Util.getBytes("subsystem"));
            buf.putByte((byte)(waitForReply() ? 1 : 0));
            buf.putString(Util.getBytes("sftp"));
            session.write(packet);

            if(reply)
            {
                while(channel.reply==-1)
                {
                    try{System.Threading.Thread.Sleep(10);}
                    catch//(Exception ee)
                    {
                    }
                }
                if(channel.reply==0)
                {
                    throw new JSchException("failed to send sftp request");
                }
            }
        }
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            packet.reset();
            buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
            buf.putInt(channel.getRecipient());
            buf.putString( Util.getBytes("signal"));
            buf.putByte((byte)(waitForReply() ? 1 : 0));
            buf.putString(Util.getBytes(signal));
            session.write(packet);
        }
Ejemplo n.º 3
0
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            // send
            // byte     SSH_MSG_CHANNEL_REQUEST(98)
            // uint32 recipient channel
            // string request type       // "shell"
            // boolean want reply        // 0
            packet.reset();
            buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
            buf.putInt(channel.getRecipient());
            buf.putString(Util.getBytes("shell"));
            buf.putByte((byte)(waitForReply() ? 1 : 0));
            session.write(packet);
        }
Ejemplo n.º 4
0
 public void request(Session session, Channel channel)
 {
     Packet packet=session.packet;
     Buffer buf=session.buf;
     // send
     // byte     SSH_MSG_CHANNEL_REQUEST(98)
     // uint32 recipient channel
     // string request type       // "exec"
     // boolean want reply        // 0
     // string command
     packet.reset();
     buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
     buf.putInt(channel.getRecipient());
     buf.putString(new Str("exec").getBytes());
     buf.putByte((byte)(waitForReply() ? 1 : 0));
     buf.putString(new Str(command).getBytes());
     session.write(packet);
 }
Ejemplo n.º 5
0
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            // byte      SSH_MSG_CHANNEL_REQUEST(98)
            // uint32 recipient channel
            // string request type        // "x11-req"
            // boolean want reply         // 0
            // boolean   single connection
            // string    x11 authentication protocol // "MIT-MAGIC-COOKIE-1".
            // string    x11 authentication cookie
            // uint32    x11 screen number
            packet.reset();
            buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
            buf.putInt(channel.getRecipient());
            buf.putString(Util.getBytes("x11-req"));
            buf.putByte((byte)(waitForReply() ? 1 : 0));
            buf.putByte((byte)0);
            buf.putString(Util.getBytes("MIT-MAGIC-COOKIE-1"));
            buf.putString(ChannelX11.getFakedCookie(session));
            buf.putInt(0);
            session.write(packet);
        }
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            //byte      SSH_MSG_CHANNEL_REQUEST
            //uint32    recipient_channel
            //string    "window-change"
            //boolean   FALSE
            //uint32    terminal width, columns
            //uint32    terminal height, rows
            //uint32    terminal width, pixels
            //uint32    terminal height, pixels
            packet.reset();
            buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
            buf.putInt(channel.getRecipient());
            buf.putString(Util.getBytes("window-change"));
            buf.putByte((byte)(waitForReply() ? 1 : 0));
            buf.putInt(width_columns);
            buf.putInt(height_rows);
            buf.putInt(width_pixels);
            buf.putInt(height_pixels);
            session.write(packet);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Connect a channel to the remote server using the 'SCP TO' command ('scp -t')
        /// </summary>
        /// <param name="channel">Will contain the new connected channel</param>
        /// <param name="server">Will contaun the new connected server I/O stream</param>
        /// <param name="rfile">The remote path on the server</param>
        /// <param name="recursive">Idicate a recursive scp transfer</param>
        protected void SCP_ConnectTo(out Channel channel, out Stream server, string rfile, bool recursive)
        {
            string scpCommand = "scp -p -t ";
            if(recursive) scpCommand += "-r ";
            scpCommand += "\""+rfile+"\"";

            channel = (ChannelExec)m_session.openChannel(ChannelType);
            ((ChannelExec)channel).setCommand(scpCommand);

            server =
                new SharpSSH.Streams.CombinedStream
                (channel.getInputStream(), channel.getOutputStream());
            channel.connect();

            SCP_CheckAck(server);
        }
Ejemplo n.º 8
0
 internal static void disconnect(Session session)
 {
     Channel[] channels=null;
     int count=0;
     lock(pool)
     {
         channels=new Channel[pool.size()];
         for(int i=0; i<pool.size(); i++)
         {
             try
             {
                 Channel c=((Channel)(pool.elementAt(i)));
                 if(c.session==session)
                 {
                     channels[count++]=c;
                 }
             }
             catch(Exception e)
             {
             }
         }
     }
     for(int i=0; i<count; i++)
     {
         channels[i].disconnect();
     }
 }
Ejemplo n.º 9
0
 internal static void del(Channel c)
 {
     lock(pool)
     {
         pool.removeElement(c);
     }
 }
 public void request(Session session, Channel channel, String subsystem, bool want_reply)
 {
     this.subsystem=subsystem;
     this.want_reply=want_reply;
     this.request(session, channel);
 }
Ejemplo n.º 11
0
 internal void addChannel(Channel channel)
 {
     channel.session=this;
 }
Ejemplo n.º 12
0
        public void write(Packet packet, Channel c, int length)
        {
            while(true)
            {
                if(in_kex)
                {
                    try{Thread.Sleep(10);}
                    catch(ThreadInterruptedException e){};
                    continue;
                }
                lock(c)
                {
                    if(c.rwsize>=length)
                    {
                        c.rwsize-=length;
                        break;
                    }
                }
                if(c._close || !c.isConnected())
                {
                    throw new IOException("channel is broken");
                }

                bool sendit=false;
                int s=0;
                byte command=0;
                int recipient=-1;
                lock(c)
                {
                    if(c.rwsize>0)
                    {
                        int len=c.rwsize;
                        if(len>length)
                        {
                            len=length;
                        }
                        if(len!=length)
                        {
                            s=packet.shift(len, (c2smac!=null ? c2smac.getBlockSize() : 0));
                        }
                        command=packet.buffer.buffer[5];
                        recipient=c.getRecipient();
                        length-=len;
                        c.rwsize-=len;
                        sendit=true;
                    }
                }
                if(sendit)
                {
                    _write(packet);
                    if(length==0)
                    {
                        return;
                    }
                    packet.unshift(command, recipient, s, length);
                    lock(c)
                    {
                        if(c.rwsize>=length)
                        {
                            c.rwsize-=length;
                            break;
                        }
                    }
                }

                try{Thread.Sleep(100);}
                catch(ThreadInterruptedException e){};
            }
            _write(packet);
        }
Ejemplo n.º 13
0
 protected virtual void ConnectChannel()
 {
     m_channel = m_session.openChannel(ChannelType);
     this.OnChannelReceived();
     m_channel.connect();
     this.OnConnected();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Closes the SSH subsystem
 /// </summary>
 public virtual void Close()
 {
     if (m_channel != null)
     {
         m_channel.disconnect();
         m_channel = null;
     }
     if (m_session != null)
     {
         m_session.disconnect();
         m_session = null;
     }
 }