Load() private static method

private static Load ( uint protocolVersion, SftpMessageTypes messageType, byte data, int offset, int count, Encoding encoding ) : SftpMessage
protocolVersion uint
messageType SftpMessageTypes
data byte
offset int
count int
encoding Encoding
return SftpMessage
コード例 #1
0
        private bool TryLoadSftpMessage(byte[] packetData, int offset, int count)
        {
            //  Load SFTP Message and handle it
            var response = SftpMessage.Load(ProtocolVersion, packetData, offset, count, Encoding);

            try
            {
                var versionResponse = response as SftpVersionResponse;
                if (versionResponse != null)
                {
                    ProtocolVersion      = versionResponse.Version;
                    _supportedExtensions = versionResponse.Extentions;

                    _sftpVersionConfirmed.Set();
                }
                else
                {
                    HandleResponse(response as SftpResponse);
                }

                return(true);
            }
            catch (Exception exp)
            {
                RaiseError(exp);
                return(false);
            }
        }
コード例 #2
0
        protected override void OnDataReceived(uint dataTypeCode, byte[] data)
        {
            //  Add channel data to internal data holder
            this._data.AddRange(data);

            while (this._data.Count > 4 + 1)
            {
                //  Extract packet length
                var packetLength = (this._data[0] << 24 | this._data[1] << 16 | this._data[2] << 8 | this._data[3]);

                //  Check if complete packet data is available
                if (this._data.Count < packetLength + 4)
                {
                    //  Wait for complete message to arrive first
                    break;
                }
                this._data.RemoveRange(0, 4);

                //  Create buffer to hold packet data
                var packetData = new byte[packetLength];

                //  Cope packet data to array
                this._data.CopyTo(0, packetData, 0, packetLength);

                //  Remove loaded data from _data holder
                this._data.RemoveRange(0, packetLength);

                //  Load SFTP Message and handle it
                var response = SftpMessage.Load(packetData);

                try
                {
                    var versionResponse = response as SftpVersionResponse;
                    if (versionResponse != null)
                    {
                        if (versionResponse.Version == 3)
                        {
                            this.Extentions = versionResponse.Extentions;
                            this._sftpVersionConfirmed.Set();
                        }
                        else
                        {
                            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Server SFTP version {0} is not supported.", versionResponse.Version));
                        }
                    }
                    else
                    {
                        this.HandleResponse(response as SftpResponse);
                    }
                }
                catch (Exception exp)
                {
                    this.RaiseError(exp);
                    break;
                }
            }
        }
コード例 #3
0
        protected override void OnDataReceived(byte[] data)
        {
            //  Add channel data to internal data holder
            _data.AddRange(data);

            while (_data.Count > 4 + 1)
            {
                //  Extract packet length
                var packetLength = (_data[0] << 24 | _data[1] << 16 | _data[2] << 8 | _data[3]);

                //  Check if complete packet data is available
                if (_data.Count < packetLength + 4)
                {
                    //  Wait for complete message to arrive first
                    break;
                }

                var packetLengthIncludingBytesForLength = packetLength + 4;

                //  Create buffer to hold packet data and 4 bytes for packet length
                var packetData = new byte[packetLengthIncludingBytesForLength];

                // copy packet data and bytes for length to array
                _data.CopyTo(0, packetData, 0, packetLengthIncludingBytesForLength);

                //  Remove loaded data and bytes for length from _data holder
                _data.RemoveRange(0, packetLengthIncludingBytesForLength);

                //  Load SFTP Message and handle it
                var response = SftpMessage.Load(ProtocolVersion, packetData, Encoding);

                try
                {
                    var versionResponse = response as SftpVersionResponse;
                    if (versionResponse != null)
                    {
                        ProtocolVersion      = versionResponse.Version;
                        _supportedExtensions = versionResponse.Extentions;

                        _sftpVersionConfirmed.Set();
                    }
                    else
                    {
                        HandleResponse(response as SftpResponse);
                    }
                }
                catch (Exception exp)
                {
                    RaiseError(exp);
                    break;
                }
            }
        }