コード例 #1
0
        public void GetBytes()
        {
            var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null);

            var bytes = request.GetBytes();

            var expectedBytesLength = 0;
            expectedBytesLength += 4; // Length
            expectedBytesLength += 1; // Type
            expectedBytesLength += 4; // RequestId
            expectedBytesLength += 4; // Handle length
            expectedBytesLength += _handle.Length; // Handle

            Assert.AreEqual(expectedBytesLength, bytes.Length);

            var sshDataStream = new SshDataStream(bytes);

            Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32());
            Assert.AreEqual((byte) SftpMessageTypes.ReadDir, sshDataStream.ReadByte());
            Assert.AreEqual(_requestId, sshDataStream.ReadUInt32());

            Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32());
            var actualHandle = new byte[_handle.Length];
            sshDataStream.Read(actualHandle, 0, actualHandle.Length);
            Assert.IsTrue(_handle.SequenceEqual(actualHandle));

            Assert.IsTrue(sshDataStream.IsEndOfData);
        }
コード例 #2
0
        public void Constructor()
        {
            var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null);

            Assert.AreSame(_handle, request.Handle);
            Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
            Assert.AreEqual(_requestId, request.RequestId);
            Assert.AreEqual(SftpMessageTypes.ReadDir, request.SftpMessageType);
        }
コード例 #3
0
        public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List<SftpStatusResponse>();
            var nameActionInvocations = new List<SftpNameResponse>();

            Action<SftpStatusResponse> statusAction = statusActionInvocations.Add;
            Action<SftpNameResponse> nameAction = nameActionInvocations.Add;
            var statusResponse = new SftpStatusResponse(_protocolVersion);

            var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
            Assert.AreEqual(0, nameActionInvocations.Count);
        }
コード例 #4
0
ファイル: SftpSession.cs プロジェクト: prtkgpt/ch4zilla
        /// <summary>
        /// Performs SSH_FXP_READDIR request
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <returns></returns>
        internal KeyValuePair<string, SftpFileAttributes>[] RequestReadDir(byte[] handle)
        {
            SshException exception = null;

            KeyValuePair<string, SftpFileAttributes>[] result = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpReadDirRequest(this.ProtocolVersion, this.NextRequestId, handle,
                    (response) =>
                    {
                        result = response.Files;
                        wait.Set();
                    },
                    (response) =>
                    {
                        if (response.StatusCode != StatusCodes.Eof)
                        {
                            exception = this.GetSftpException(response);
                        }
                        wait.Set();
                    });

                this.SendRequest(request);

                this.WaitHandle(wait, this._operationTimeout);
            }

            if (exception != null)
            {
                throw exception;
            }

            return result;
        }
コード例 #5
0
        /// <summary>
        /// Performs SSH_FXP_READDIR request
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <returns></returns>
        internal IDictionary<string, SftpFileAttributes> RequestReadDir(byte[] handle)
        {
            IDictionary<string, SftpFileAttributes> result = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpReadDirRequest(this.NextRequestId, handle,
                    (response) =>
                    {
                        result = response.Files;
                        wait.Set();
                    },
                    (response) =>
                    {
                        if (response.StatusCode == StatusCodes.Eof)
                        {
                            wait.Set();
                        }
                        else
                        {
                            this.ThrowSftpException(response);
                        }
                    });

                this.SendRequest(request);

                this.WaitHandle(wait, this._operationTimeout);
            }

            return result;
        }