예제 #1
0
        public void Constructor()
        {
            var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null);

            Assert.AreSame(_handle, request.Handle);
            Assert.AreEqual(_name, request.Name);
            Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
            Assert.AreEqual(_requestId, request.RequestId);
            Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType);
        }
예제 #2
0
        public void Complete_SftpExtendedReplyResponse()
        {
            IList <SftpStatusResponse>        statusActionInvocations        = new List <SftpStatusResponse>();
            IList <SftpExtendedReplyResponse> extendedReplyActionInvocations = new List <SftpExtendedReplyResponse>();

            Action <SftpExtendedReplyResponse> extendedAction = extendedReplyActionInvocations.Add;
            Action <SftpStatusResponse>        statusAction   = statusActionInvocations.Add;
            var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion);

            var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction);

            request.Complete(extendedReplyResponse);

            Assert.AreEqual(0, statusActionInvocations.Count);
            Assert.AreEqual(1, extendedReplyActionInvocations.Count);
            Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]);
        }
예제 #3
0
        /// <summary>
        /// Performs [email protected] extended request.
        /// </summary>
        /// <param name="handle">The file handle.</param>
        /// <param name="nullOnError">if set to <c>true</c> [null on error].</param>
        /// <returns></returns>
        /// <exception cref="System.NotSupportedException"></exception>
        internal SftpFileSytemInformation RequestFStatVfs(byte[] handle, bool nullOnError = false)
        {
            if (this.ProtocolVersion < 3)
            {
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
            }

            SshException exception = null;

            SftpFileSytemInformation information = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new FStatVfsRequest(this.ProtocolVersion, this.NextRequestId, handle,
                                                  (response) =>
                {
                    information = response.GetReply <StatVfsReplyInfo>().Information;

                    wait.Set();
                },
                                                  (response) =>
                {
                    exception = this.GetSftpException(response);
                    wait.Set();
                });

                if (!this._supportedExtensions.ContainsKey(request.Name))
                {
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name));
                }

                this.SendRequest(request);

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

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

            return(information);
        }
예제 #4
0
        public void GetBytes()
        {
            var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null);

            var bytes = request.GetBytes();

            var expectedBytesLength = 0;

#if TUNING
            expectedBytesLength += 4;                 // Length
#endif
            expectedBytesLength += 1;                 // Type
            expectedBytesLength += 4;                 // RequestId
            expectedBytesLength += 4;                 // Name length
            expectedBytesLength += _nameBytes.Length; // Name
            expectedBytesLength += 4;                 // Handle length
            expectedBytesLength += _handle.Length;    // Handle

            Assert.AreEqual(expectedBytesLength, bytes.Length);

            var sshDataStream = new SshDataStream(bytes);

#if TUNING
            Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32());
#endif
            Assert.AreEqual((byte)SftpMessageTypes.Extended, sshDataStream.ReadByte());
            Assert.AreEqual(_requestId, sshDataStream.ReadUInt32());
            Assert.AreEqual((uint)_nameBytes.Length, sshDataStream.ReadUInt32());

            var actualNameBytes = new byte[_nameBytes.Length];
            sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length);
            Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes));

            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);
        }