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 SftpVersionResponse Build() { var sftpVersionResponse = new SftpVersionResponse() { Version = _version, Extentions = _extensions }; return(sftpVersionResponse); }
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); }
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); }