public void Constructor()
        {
            var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null);

            Assert.AreSame(_encoding, request.Encoding);
            Assert.AreEqual(_path, request.Path);
            Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
            Assert.AreEqual(_requestId, request.RequestId);
            Assert.AreEqual(SftpMessageTypes.SetStat, request.SftpMessageType);
        }
        public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List <SftpStatusResponse>();
            Action <SftpStatusResponse> statusAction = statusActionInvocations.Add;
            var statusResponse = new SftpStatusResponse(_protocolVersion);

            var request = new SftpSetStatRequest(
                _protocolVersion,
                _requestId,
                _path,
                _encoding,
                _attributes,
                statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
        }
示例#3
0
        /// <summary>
        /// Performs SSH_FXP_SETSTAT request.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="attributes">The attributes.</param>
        internal void RequestSetStat(string path, SftpFileAttributes attributes)
        {
            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpSetStatRequest(this.NextRequestId, path, attributes,
                                                     (response) =>
                {
                    if (response.StatusCode == StatusCodes.Ok)
                    {
                        wait.Set();
                    }
                    else
                    {
                        this.ThrowSftpException(response);
                    }
                });

                this.SendRequest(request);

                this.WaitHandle(wait, this._operationTimeout);
            }
        }
示例#4
0
        public void GetBytes()
        {
            var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null);

            var bytes = request.GetBytes();

            var expectedBytesLength = 0;

#if TUNING
            expectedBytesLength += 4;                       // Length
#endif
            expectedBytesLength += 1;                       // Type
            expectedBytesLength += 4;                       // RequestId
            expectedBytesLength += 4;                       // Path length
            expectedBytesLength += _pathBytes.Length;       // Path
            expectedBytesLength += _attributesBytes.Length; // Attributes

            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.SetStat, sshDataStream.ReadByte());
            Assert.AreEqual(_requestId, sshDataStream.ReadUInt32());

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

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

            Assert.IsTrue(sshDataStream.IsEndOfData);
        }
示例#5
0
        /// <summary>
        /// Performs SSH_FXP_SETSTAT request.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="attributes">The attributes.</param>
        internal void RequestSetStat(string path, SftpFileAttributes attributes)
        {
            SshException exception = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpSetStatRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding, attributes,
                                                     (response) =>
                {
                    exception = this.GetSftpException(response);
                    wait.Set();
                });

                this.SendRequest(request);

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

            if (exception != null)
            {
                throw exception;
            }
        }
示例#6
0
        /// <summary>
        /// Performs SSH_FXP_SETSTAT request.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="attributes">The attributes.</param>
        public void RequestSetStat(string path, SftpFileAttributes attributes)
        {
            SshException exception = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpSetStatRequest(ProtocolVersion, NextRequestId, path, Encoding, attributes,
                                                     response =>
                {
                    exception = GetSftpException(response);
                    wait.Set();
                });

                SendRequest(request);

                WaitOnHandle(wait, OperationTimeout);
            }

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