Example #1
0
        /// <summary>
        /// Sends a global request.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="wantreply"></param>
        /// <returns></returns>
        public bool SendGlobalRequest(GlobalRequest request, bool wantreply)
        {
            try
            {
                SSHPacket packet = GetPacket();
                packet.WriteByte(SSH_MSG_GLOBAL_REQUEST);
                packet.WriteString(request.Name);
                packet.WriteBool(wantreply);
                if (request.Data != null)
                {
                    packet.WriteBytes(request.Data);
                }

#if DEBUG
                System.Diagnostics.Trace.WriteLine("Sending SSH_MSG_GLOBAL_REQUEST");
                System.Diagnostics.Trace.WriteLine(request.Name);
#endif
                SendMessage(packet);

                if (wantreply)
                {
                    packet = GlobalMessages.NextMessage(GLOBAL_REQUEST_MESSAGES);
                    if (packet.MessageID == SSH_MSG_REQUEST_SUCCESS)
                    {
                        if (packet.Available > 1)
                        {
                            byte[] tmp = new byte[packet.Available];
                            packet.ReadBytes(tmp);
                            request.Data = tmp;
                        }
                        else
                        {
                            request.Data = null;
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            catch (System.IO.IOException ex)
            {
                throw new SSHException(ex.Message, SSHException.INTERNAL_ERROR);
            }
        }
Example #2
0
        /// <summary>
        /// Sends a channel request. Many channels have extensions that are specific to that particular
        /// channel type, an example of which is requesting a pseudo terminal from an interactive session.
        /// </summary>
        /// <param name="requesttype">the name of the request, for example "pty-req"</param>
        /// <param name="wantreply">specifies whether the remote side should send a success/failure message</param>
        /// <param name="requestdata">the request data</param>
        /// <returns></returns>
        public bool SendRequest(System.String requesttype, bool wantreply, byte[] requestdata)
        {
            lock (this)
            {
                try
                {
                    SSHPacket packet = connection.GetPacket();
                    packet.WriteByte((System.Byte)SSH_MSG_CHANNEL_REQUEST);
                    packet.WriteUINT32(remoteid);
                    packet.WriteString(requesttype);
                    packet.WriteBool(wantreply);
                    if (requestdata != null)
                    {
                        packet.WriteBytes(requestdata);
                    }

#if DEBUG
                    System.Diagnostics.Trace.WriteLine("Sending SSH_MSG_CHANNEL_REQUEST " + requesttype);
                    System.Diagnostics.Trace.WriteLine("Channelid=" + ChannelID);
#endif
                    connection.SendMessage(packet);

                    bool result = false;

                    if (wantreply)
                    {
                        packet = ProcessMessages(CHANNEL_REQUEST_MESSAGES);
                        return(packet.MessageID == SSH_MSG_CHANNEL_SUCCESS);
                    }

                    return(result);
                }
                catch (System.IO.IOException ex)
                {
                    throw new SSHException(ex.Message, SSHException.INTERNAL_ERROR);
                }
            }
        }