Inheritance: SftpResponse
コード例 #1
0
        public void Load()
        {
            var target = new SftpAttrsResponse(_protocolVersion);
            var attributes = CreateSftpFileAttributes();
            var attributesBytes = attributes.GetBytes();

            var sshDataStream = new SshDataStream(4 + 1 + 4 + attributesBytes.Length);
            sshDataStream.Position = 4; // skip 4 bytes for SSH packet length
            sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs);
            sshDataStream.Write(_responseId);
            sshDataStream.Write(attributesBytes, 0, attributesBytes.Length);

            target.Load(sshDataStream.ToArray());

            Assert.IsNotNull(target.Attributes);
            Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
            Assert.AreEqual(_responseId, target.ResponseId);
            Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType);

            // check attributes in detail
            Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId);
            Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime);
            Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime);
            Assert.AreEqual(attributes.UserId, target.Attributes.UserId);
        }
コード例 #2
0
        public void Constructor()
        {
            var target = new SftpAttrsResponse(_protocolVersion);

            Assert.IsNull(target.Attributes);
            Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
            Assert.AreEqual((uint) 0, target.ResponseId);
            Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType);
        }
コード例 #3
0
        public void Complete_SftpAttrsResponse()
        {
            var statusActionInvocations = new List<SftpStatusResponse>();
            var attrsActionInvocations = new List<SftpAttrsResponse>();
            Action<SftpStatusResponse> statusAction = statusActionInvocations.Add;
            Action<SftpAttrsResponse> attrsAction = attrsActionInvocations.Add;
            var attrsResponse = new SftpAttrsResponse(_protocolVersion);

            var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction);

            request.Complete(attrsResponse);

            Assert.AreEqual(0, statusActionInvocations.Count);
            Assert.AreEqual(1, attrsActionInvocations.Count);
            Assert.AreSame(attrsResponse, attrsActionInvocations[0]);
        }
コード例 #4
0
ファイル: SftpMessage.cs プロジェクト: npcook/terminal
        private static SftpMessage Load(uint protocolVersion, byte[] data, SftpMessageTypes messageType, Encoding encoding)
        {
            SftpMessage message;

            switch (messageType)
            {
                case SftpMessageTypes.Version:
                    message = new SftpVersionResponse();
                    break;
                case SftpMessageTypes.Status:
                    message = new SftpStatusResponse(protocolVersion);
                    break;
                case SftpMessageTypes.Data:
                    message = new SftpDataResponse(protocolVersion);
                    break;
                case SftpMessageTypes.Handle:
                    message = new SftpHandleResponse(protocolVersion);
                    break;
                case SftpMessageTypes.Name:
                    message = new SftpNameResponse(protocolVersion, encoding);
                    break;
                case SftpMessageTypes.Attrs:
                    message = new SftpAttrsResponse(protocolVersion);
                    break;
                case SftpMessageTypes.ExtendedReply:
                    message = new SftpExtendedReplyResponse(protocolVersion);
                    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;
        }