コード例 #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
ファイル: SftpSession.cs プロジェクト: DynamicDevices/dta
        internal void SendMessage(SftpMessage sftpMessage)
        {
            var messageData = sftpMessage.GetBytes();

            var data = new byte[4 + messageData.Length];

            ((uint)messageData.Length).GetBytes().CopyTo(data, 0);
            messageData.CopyTo(data, 4);

            this.SendData(data);
        }
コード例 #4
0
ファイル: SftpSession.cs プロジェクト: cpascal/win-sshfs
        internal void SendMessage(SftpMessage sftpMessage)
        {
            var messageData = sftpMessage.GetBytes();

            var data = new byte[4 + messageData.Length];

            ((uint)messageData.Length).GetBytes().CopyTo(data, 0);
            messageData.CopyTo(data, 4);

            this.SendData(data);
        }
コード例 #5
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;
                }
            }
        }
コード例 #6
0
ファイル: SftpDataMessage.cs プロジェクト: npcook/terminal
        public SftpDataMessage(uint localChannelNumber, SftpMessage sftpMessage)
        {
            this.LocalChannelNumber = localChannelNumber;

            var messageData = sftpMessage.GetBytes();

            var data = new byte[4 + messageData.Length];

            ((uint)messageData.Length).GetBytes().CopyTo(data, 0);
            messageData.CopyTo(data, 4);
            this.Data = data;
        }
コード例 #7
0
        public SftpDataMessage(uint localChannelNumber, SftpMessage sftpMessage)
        {
            this.LocalChannelNumber = localChannelNumber;

            var messageData = sftpMessage.GetBytes();

            var data = new byte[4 + messageData.Length];

            ((uint)messageData.Length).GetBytes().CopyTo(data, 0);
            messageData.CopyTo(data, 4);
            this.Data = data;
        }
コード例 #8
0
        internal void SendMessage(SftpMessage sftpMessage)
        {
#if TUNING
            var data = sftpMessage.GetBytes();
#else
            var messageData = sftpMessage.GetBytes();

            var data = new byte[4 + messageData.Length];

            ((uint)messageData.Length).GetBytes().CopyTo(data, 0);
            messageData.CopyTo(data, 4);
#endif

            SendData(data);
        }
コード例 #9
0
        private static SftpMessage Load(byte[] data, SftpMessageTypes messageType)
        {
            SftpMessage message = null;

            switch (messageType)
            {
            case SftpMessageTypes.Version:
                message = new SftpVersionResponse();
                break;

            case SftpMessageTypes.Status:
                message = new SftpStatusResponse();
                break;

            case SftpMessageTypes.Data:
                message = new SftpDataResponse();
                break;

            case SftpMessageTypes.Handle:
                message = new SftpHandleResponse();
                break;

            case SftpMessageTypes.Name:
                message = new SftpNameResponse();
                break;

            case SftpMessageTypes.Attrs:
                message = new SftpAttrsResponse();
                break;

            case SftpMessageTypes.ExtendedReply:
                message = new SftpExtendedReplyResponse();
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Message type '{0}' is not supported.", messageType));
            }

            message.LoadBytes(data);

            message.ResetReader();

            message.LoadData();

            return(message);
        }
コード例 #10
0
 internal void SendMessage(SftpMessage sftpMessage)
 {
     this._session.SendMessage(new SftpDataMessage(this._channel.RemoteChannelNumber, sftpMessage));
 }
コード例 #11
0
        internal void SendMessage(SftpMessage sftpMessage)
        {
            var data = sftpMessage.GetBytes();

            SendData(data);
        }
コード例 #12
0
ファイル: SftpSession.cs プロジェクト: sshnet/SSH.NET
 internal void SendMessage(SftpMessage sftpMessage)
 {
     var data = sftpMessage.GetBytes();
     SendData(data);
 }
コード例 #13
0
ファイル: SftpSession.cs プロジェクト: InoMurko/win-sshfs
 internal void SendMessage(SftpMessage sftpMessage)
 {
     this.SendData(new SftpDataMessage(this.ChannelNumber, sftpMessage));
 }
コード例 #14
0
 internal void SendMessage(SftpMessage sftpMessage)
 {
     this.SendData(new SftpDataMessage(this.ChannelNumber, sftpMessage));
 }