<PackageReference Include="SSH.NET" Version="2016.0.0" />

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 ZeroReaderIndex => 5; protected override int BufferCapacity => ZeroReaderIndex; public abstract SftpMessageTypes SftpMessageType { get; } public static SftpMessage Load(uint protocolVersion, byte[] data, Encoding encoding) { SftpMessageTypes messageType = (SftpMessageTypes)data[4]; return Load(protocolVersion, data, messageType, 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, byte[] data, SftpMessageTypes messageType, 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.", messageType)); } sftpMessage.Load(data); return sftpMessage; } public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "SFTP Message : {0}", SftpMessageType); } } }