| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Sftp.Responses; |
| | | 4 | | |
| | | 5 | | namespace Renci.SshNet.Sftp.Requests |
| | | 6 | | { |
| | | 7 | | internal sealed class SftpReadRequest : SftpRequest |
| | | 8 | | { |
| | | 9 | | private readonly Action<SftpDataResponse> _dataAction; |
| | | 10 | | |
| | | 11 | | public override SftpMessageTypes SftpMessageType |
| | | 12 | | { |
| | 12312 | 13 | | get { return SftpMessageTypes.Read; } |
| | | 14 | | } |
| | | 15 | | |
| | 12315 | 16 | | public byte[] Handle { get; private set; } |
| | | 17 | | |
| | 8214 | 18 | | public ulong Offset { get; private set; } |
| | | 19 | | |
| | 8214 | 20 | | public uint Length { get; private set; } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Gets the size of the message in bytes. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <value> |
| | | 26 | | /// The size of the messages in bytes. |
| | | 27 | | /// </value> |
| | | 28 | | protected override int BufferCapacity |
| | | 29 | | { |
| | | 30 | | get |
| | 4101 | 31 | | { |
| | 4101 | 32 | | var capacity = base.BufferCapacity; |
| | 4101 | 33 | | capacity += 4; // Handle length |
| | 4101 | 34 | | capacity += Handle.Length; // Handle |
| | 4101 | 35 | | capacity += 8; // Offset |
| | 4101 | 36 | | capacity += 4; // Length |
| | 4101 | 37 | | return capacity; |
| | 4101 | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public SftpReadRequest(uint protocolVersion, uint requestId, byte[] handle, ulong offset, uint length, Action<Sf |
| | 4110 | 42 | | : base(protocolVersion, requestId, statusAction) |
| | 4110 | 43 | | { |
| | 4110 | 44 | | Handle = handle; |
| | 4110 | 45 | | Offset = offset; |
| | 4110 | 46 | | Length = length; |
| | 4110 | 47 | | _dataAction = dataAction; |
| | 4110 | 48 | | } |
| | | 49 | | |
| | | 50 | | protected override void LoadData() |
| | 0 | 51 | | { |
| | 0 | 52 | | base.LoadData(); |
| | | 53 | | |
| | 0 | 54 | | Handle = ReadBinary(); |
| | 0 | 55 | | Offset = ReadUInt64(); |
| | 0 | 56 | | Length = ReadUInt32(); |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | protected override void SaveData() |
| | 4101 | 60 | | { |
| | 4101 | 61 | | base.SaveData(); |
| | | 62 | | |
| | 4101 | 63 | | WriteBinaryString(Handle); |
| | 4101 | 64 | | Write(Offset); |
| | 4101 | 65 | | Write(Length); |
| | 4101 | 66 | | } |
| | | 67 | | |
| | | 68 | | public override void Complete(SftpResponse response) |
| | 4086 | 69 | | { |
| | 4086 | 70 | | if (response is SftpDataResponse dataResponse) |
| | 3970 | 71 | | { |
| | 3970 | 72 | | _dataAction(dataResponse); |
| | 3970 | 73 | | } |
| | | 74 | | else |
| | 116 | 75 | | { |
| | 116 | 76 | | base.Complete(response); |
| | 116 | 77 | | } |
| | 4086 | 78 | | } |
| | | 79 | | } |
| | | 80 | | } |