<PackageReference Include="SSH.NET" Version="2016.1.0-beta1" />

SftpMessage

abstract class SftpMessage : SshData
using Renci.SshNet.Common; using Renci.SshNet.Sftp.Responses; using System; using System.Globalization; using System.IO; using System.Text; namespace Renci.SshNet.Sftp { internal abstract class SftpMessage : SshData { protected override int BufferCapacity => 5; public abstract SftpMessageTypes SftpMessageType { get; } public static SftpMessage Load(uint protocolVersion, byte[] data, int offset, int count, Encoding encoding) { SftpMessageTypes messageType = (SftpMessageTypes)data[offset]; return Load(protocolVersion, messageType, data, offset + 1, count - 1, encoding); } protected override void LoadData() { } protected override void SaveData() { Write((byte)SftpMessageType); } protected override void WriteBytes(SshDataStream stream) { long position = stream.Position; stream.Seek(4, SeekOrigin.Current); base.WriteBytes(stream); long position2 = stream.Position; long num = position2 - position - 4; stream.Position = position; stream.Write((uint)num); stream.Position = position2; } protected SftpFileAttributes ReadAttributes() { return SftpFileAttributes.FromBytes(base.DataStream); } private static SftpMessage Load(uint protocolVersion, SftpMessageTypes messageType, byte[] data, int offset, int count, Encoding encoding) { SftpMessage sftpMessage; switch (messageType) { case SftpMessageTypes.Version: sftpMessage = new SftpVersionResponse(); break; case SftpMessageTypes.Status: sftpMessage = new SftpStatusResponse(protocolVersion); break; case SftpMessageTypes.Data: sftpMessage = new SftpDataResponse(protocolVersion); break; case SftpMessageTypes.Handle: sftpMessage = new SftpHandleResponse(protocolVersion); break; case SftpMessageTypes.Name: sftpMessage = new SftpNameResponse(protocolVersion, encoding); break; case SftpMessageTypes.Attrs: sftpMessage = new SftpAttrsResponse(protocolVersion); break; case SftpMessageTypes.ExtendedReply: sftpMessage = new SftpExtendedReplyResponse(protocolVersion); break; default: throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Message type '{0}' is not supported.", new object[1] { messageType })); } sftpMessage.Load(data, offset, count); return sftpMessage; } public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "SFTP Message : {0}", new object[1] { SftpMessageType }); } } }