private void SetupData() { var random = new Random(); #region SftpSession.Connect() _operationTimeout = random.Next(100, 500); _protocolVersion = (uint)random.Next(0, 3); _encoding = Encoding.UTF8; _sftpInitRequestBytes = new SftpInitRequestBuilder().WithVersion(SftpSession.MaximumSupportedVersion) .Build() .GetBytes(); _sftpVersionResponse = new SftpVersionResponseBuilder().WithVersion(_protocolVersion) .Build(); _sftpRealPathRequestBytes = new SftpRealPathRequestBuilder().WithProtocolVersion(_protocolVersion) .WithRequestId(1) .WithPath(".") .WithEncoding(_encoding) .Build() .GetBytes(); _sftpNameResponse = new SftpNameResponseBuilder().WithProtocolVersion(_protocolVersion) .WithResponseId(1) .WithEncoding(_encoding) .WithFile("/ABC", SftpFileAttributes.Empty) .Build(); #endregion SftpSession.Connect() _path = random.Next().ToString(); _handle = CryptoAbstraction.GenerateRandom(4); _offset = (uint)random.Next(1, 5); _length = (uint)random.Next(30, 50); _data = CryptoAbstraction.GenerateRandom(200); _sftpOpenRequestBytes = new SftpOpenRequestBuilder().WithProtocolVersion(_protocolVersion) .WithRequestId(2) .WithFileName(_path) .WithFlags(Flags.Read) .WithEncoding(_encoding) .Build() .GetBytes(); _sftpHandleResponseBytes = new SftpHandleResponseBuilder().WithProtocolVersion(_protocolVersion) .WithResponseId(2) .WithHandle(_handle) .Build() .GetBytes(); _sftpReadRequestBytes = new SftpReadRequestBuilder().WithProtocolVersion(_protocolVersion) .WithRequestId(3) .WithHandle(_handle) .WithOffset(_offset) .WithLength(_length) .Build() .GetBytes(); _sftpDataResponseBytes = new SftpDataResponseBuilder().WithProtocolVersion(_protocolVersion) .WithResponseId(3) .WithData(_data) .Build() .GetBytes(); }
public SftpNameResponse Build() { var sftpNameResponse = new SftpNameResponse(_protocolVersion, _encoding) { ResponseId = _responseId, Files = _files.ToArray() }; return(sftpNameResponse); }
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)); } #if TUNING message.Load(data); #else message.LoadBytes(data); message.ResetReader(); message.LoadData(); #endif return(message); }
public void Complete_SftpNameResponse() { var statusActionInvocations = new List <SftpStatusResponse>(); var nameActionInvocations = new List <SftpNameResponse>(); Action <SftpStatusResponse> statusAction = statusActionInvocations.Add; Action <SftpNameResponse> nameAction = nameActionInvocations.Add; var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); var request = new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); request.Complete(nameResponse); Assert.AreEqual(0, statusActionInvocations.Count); Assert.AreEqual(1, nameActionInvocations.Count); Assert.AreSame(nameResponse, nameActionInvocations[0]); }
private void SetupData() { var random = new Random(); #region SftpSession.Connect() _operationTimeout = random.Next(100, 500); _encoding = Encoding.UTF8; _protocolVersion = 3; _sftpResponseFactory = new SftpResponseFactory(); _sftpInitRequestBytes = new SftpInitRequestBuilder().WithVersion(SftpSession.MaximumSupportedVersion) .Build() .GetBytes(); _sftpVersionResponse = new SftpVersionResponseBuilder().WithVersion(_protocolVersion) .WithExtension("*****@*****.**", "") .Build(); _sftpRealPathRequestBytes = new SftpRealPathRequestBuilder().WithProtocolVersion(_protocolVersion) .WithRequestId(1) .WithPath(".") .WithEncoding(_encoding) .Build() .GetBytes(); _sftpNameResponse = new SftpNameResponseBuilder().WithProtocolVersion(_protocolVersion) .WithResponseId(1U) .WithEncoding(_encoding) .WithFile("ABC", SftpFileAttributes.Empty) .Build(); #endregion SftpSession.Connect() _path = random.Next().ToString(); _bAvail = (ulong)random.Next(0, int.MaxValue); _sftpStatVfsRequestBytes = new SftpStatVfsRequestBuilder().WithProtocolVersion(_protocolVersion) .WithRequestId(2) .WithPath(_path) .WithEncoding(_encoding) .Build() .GetBytes(); _sftpStatVfsResponse = new SftpStatVfsResponseBuilder().WithProtocolVersion(_protocolVersion) .WithResponseId(2U) .WithBAvail(_bAvail) .Build(); }
public SftpMessage Create(uint protocolVersion, byte messageType, Encoding encoding) { var sftpMessageType = (SftpMessageTypes)messageType; SftpMessage message; switch (sftpMessageType) { 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.", sftpMessageType)); } return(message); }