private bool _isDisposed = false; // True if object has been disposed.

        #endregion Fields

        #region Constructors

        public SshWinConsoleChannel(ChannelOpenRequestEventArgs requestEventArgs)
            : base(requestEventArgs)
        {
        }
예제 #2
0
        private bool _isDisposed = false; // True if object has been disposed.

        #endregion Fields

        #region Constructors

        public SshChannel(ChannelOpenRequestEventArgs requestEventArgs)
            : this(requestEventArgs.ClientChannel, requestEventArgs.ServerChannel,
            requestEventArgs.InitialWindowSize, requestEventArgs.MaxPacketSize)
        {
        }
        protected void ProcessMsgChannelOpen(SshStreamReader msgReader)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Read channel information.
            string channelType       = msgReader.ReadString();
            uint   senderChannel     = msgReader.ReadUInt32();
            uint   initialWindowSize = msgReader.ReadUInt32();
            uint   maxPacketSize     = msgReader.ReadUInt32();

            // Check channel type.
            switch (channelType)
            {
            default:
                // Raise event to request channel.
                var channelRequestedEventArgs = new ChannelOpenRequestEventArgs(senderChannel,
                                                                                (uint)_channels.Count, channelType, initialWindowSize, maxPacketSize);

                if (ChannelOpenRequest != null)
                {
                    ChannelOpenRequest(this, channelRequestedEventArgs);
                }

                var channel = channelRequestedEventArgs.Channel;

                // Check if channel was created.
                if (channel != null)
                {
                    channel.Opened          += new EventHandler <EventArgs>(channel_Opened);
                    channel.Closed          += new EventHandler <EventArgs>(channel_Closed);
                    channel.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(
                        channel_PropertyChanged);
                    channel.Open(this);

                    _channels.Add(channel);

                    // Send confirmation message.
                    SendMsgChannelOpenConfirmation(channel);
                }
                else
                {
                    string failureDescription = channelRequestedEventArgs.FailureDescription;

                    if (failureDescription != null)
                    {
                        // Create description of failure from reason code.
                        switch (channelRequestedEventArgs.FailureReason)
                        {
                        case SshChannelOpenFailureReason.AdministrativelyProhibited:
                            failureDescription = "Administratively prohibited.";
                            break;

                        case SshChannelOpenFailureReason.ConnectFailed:
                            failureDescription = "Connect attempt failed.";
                            break;

                        case SshChannelOpenFailureReason.UnknownChannelType:
                            failureDescription = string.Format("Unknown channel type '{0}'.",
                                                               channelType);
                            break;

                        case SshChannelOpenFailureReason.ResourceShortage:
                            failureDescription = "Resource shortage on server.";
                            break;
                        }
                    }

                    // Channel open request has failed.
                    SendMsgChannelOpenFailure(channel, channelRequestedEventArgs.FailureReason,
                                              failureDescription, "");
                    return;
                }

                break;
            }
        }
예제 #4
0
        private void connService_ChannelOpenRequest(object sender, ChannelOpenRequestEventArgs e)
        {
            var channel = new SshWinConsoleChannel(e);

            e.Channel = channel;
            // e.FailureReason = SshChannelOpenFailureReason.UnknownChannelType;
        }
        protected void ProcessMsgChannelOpen(SshStreamReader msgReader)
        {
            if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName);

            // Read channel information.
            string channelType = msgReader.ReadString();
            uint senderChannel = msgReader.ReadUInt32();
            uint initialWindowSize = msgReader.ReadUInt32();
            uint maxPacketSize = msgReader.ReadUInt32();

            // Check channel type.
            switch (channelType)
            {
                default:
                    // Raise event to request channel.
                    var channelRequestedEventArgs = new ChannelOpenRequestEventArgs(senderChannel,
                        (uint)_channels.Count, channelType, initialWindowSize, maxPacketSize);

                    if (ChannelOpenRequest != null) ChannelOpenRequest(this, channelRequestedEventArgs);

                    var channel = channelRequestedEventArgs.Channel;

                    // Check if channel was created.
                    if (channel != null)
                    {
                        channel.Opened += new EventHandler<EventArgs>(channel_Opened);
                        channel.Closed += new EventHandler<EventArgs>(channel_Closed);
                        channel.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(
                            channel_PropertyChanged);
                        channel.Open(this);

                        _channels.Add(channel);

                        // Send confirmation message.
                        SendMsgChannelOpenConfirmation(channel);
                    }
                    else
                    {
                        string failureDescription = channelRequestedEventArgs.FailureDescription;

                        if (failureDescription != null)
                        {
                            // Create description of failure from reason code.
                            switch (channelRequestedEventArgs.FailureReason)
                            {
                                case SshChannelOpenFailureReason.AdministrativelyProhibited:
                                    failureDescription = "Administratively prohibited.";
                                    break;
                                case SshChannelOpenFailureReason.ConnectFailed:
                                    failureDescription = "Connect attempt failed.";
                                    break;
                                case SshChannelOpenFailureReason.UnknownChannelType:
                                    failureDescription = string.Format("Unknown channel type '{0}'.",
                                        channelType);
                                    break;
                                case SshChannelOpenFailureReason.ResourceShortage:
                                    failureDescription = "Resource shortage on server.";
                                    break;
                            }
                        }

                        // Channel open request has failed.
                        SendMsgChannelOpenFailure(channel, channelRequestedEventArgs.FailureReason,
                            failureDescription, "");
                        return;
                    }

                    break;
            }
        }
        private bool _isDisposed = false;               // True if object has been disposed.

        public SshSessionChannel(ChannelOpenRequestEventArgs requestEventArgs)
            : base(requestEventArgs)
        {
        }
        private bool _isDisposed = false; // True if object has been disposed.

        #endregion Fields

        #region Constructors

        public SshSessionChannel(ChannelOpenRequestEventArgs requestEventArgs)
            : base(requestEventArgs)
        {
        }
        private bool _isDisposed = false;            // True if object has been disposed.

        public SshChannel(ChannelOpenRequestEventArgs requestEventArgs)
            : this(requestEventArgs.ClientChannel, requestEventArgs.ServerChannel,
                   requestEventArgs.InitialWindowSize, requestEventArgs.MaxPacketSize)
        {
        }