public void Constructor()
        {
            var target = new SftpExtendedReplyResponse(_protocolVersion);

            Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
            Assert.AreEqual((uint) 0, target.ResponseId);
            Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType);
        }
        public void GetReply_StatVfsReplyInfo()
        {
            var bsize = (ulong) _random.Next(0, int.MaxValue);
            var frsize = (ulong) _random.Next(0, int.MaxValue);
            var blocks = (ulong) _random.Next(0, int.MaxValue);
            var bfree = (ulong) _random.Next(0, int.MaxValue);
            var bavail = (ulong) _random.Next(0, int.MaxValue);
            var files = (ulong) _random.Next(0, int.MaxValue);
            var ffree = (ulong) _random.Next(0, int.MaxValue);
            var favail = (ulong) _random.Next(0, int.MaxValue);
            var sid = (ulong) _random.Next(0, int.MaxValue);
            var namemax = (ulong) _random.Next(0, int.MaxValue);

            var sshDataStream = new SshDataStream(4 + 1 + 4 + 88);
            sshDataStream.Position = 4; // skip 4 bytes for SSH packet length
            sshDataStream.WriteByte((byte)SftpMessageTypes.Attrs);
            sshDataStream.Write(_responseId);
            sshDataStream.Write(bsize);
            sshDataStream.Write(frsize);
            sshDataStream.Write(blocks);
            sshDataStream.Write(bfree);
            sshDataStream.Write(bavail);
            sshDataStream.Write(files);
            sshDataStream.Write(ffree);
            sshDataStream.Write(favail);
            sshDataStream.Write(sid);
            sshDataStream.Write((ulong) 0x2);
            sshDataStream.Write(namemax);

            var sshData = sshDataStream.ToArray();

            var target = new SftpExtendedReplyResponse(_protocolVersion);
            target.Load(sshData, 5, sshData.Length - 5);

            var reply = target.GetReply<StatVfsReplyInfo>();
            Assert.IsNotNull(reply);

            var information = reply.Information;
            Assert.IsNotNull(information);
            Assert.AreEqual(bavail, information.AvailableBlocks);
            Assert.AreEqual(favail, information.AvailableNodes);
            Assert.AreEqual(frsize, information.BlockSize);
            Assert.AreEqual(bsize, information.FileSystemBlockSize);
            Assert.AreEqual(bfree, information.FreeBlocks);
            Assert.AreEqual(ffree, information.FreeNodes);
            Assert.IsFalse(information.IsReadOnly);
            Assert.AreEqual(namemax, information.MaxNameLenght);
            Assert.AreEqual(sid, information.Sid);
            Assert.IsFalse(information.SupportsSetUid);
            Assert.AreEqual(blocks, information.TotalBlocks);
            Assert.AreEqual(files, information.TotalNodes);
        }
        public void Load()
        {
            var target = new SftpExtendedReplyResponse(_protocolVersion);

            var sshDataStream = new SshDataStream(4);
            sshDataStream.Write(_responseId);

            target.Load(sshDataStream.ToArray());

            Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
            Assert.AreEqual(_responseId, target.ResponseId);
            Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType);
        }
        public void Load()
        {
            var target = new SftpExtendedReplyResponse(_protocolVersion);

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

            target.Load(sshDataStream.ToArray());

            Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
            Assert.AreEqual(_responseId, target.ResponseId);
            Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType);
        }
示例#5
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 StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction);

            request.Complete(extendedReplyResponse);

            Assert.AreEqual(0, statusActionInvocations.Count);
            Assert.AreEqual(1, extendedReplyActionInvocations.Count);
            Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]);
        }
示例#6
0
        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;
        }