| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Sftp.Responses; |
| | | 4 | | |
| | | 5 | | namespace Renci.SshNet.Sftp.Requests |
| | | 6 | | { |
| | | 7 | | internal sealed class SftpReadDirRequest : SftpRequest |
| | | 8 | | { |
| | | 9 | | private readonly Action<SftpNameResponse> _nameAction; |
| | | 10 | | |
| | | 11 | | public override SftpMessageTypes SftpMessageType |
| | | 12 | | { |
| | 402 | 13 | | get { return SftpMessageTypes.ReadDir; } |
| | | 14 | | } |
| | | 15 | | |
| | 405 | 16 | | public byte[] Handle { get; private set; } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the size of the message in bytes. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <value> |
| | | 22 | | /// The size of the messages in bytes. |
| | | 23 | | /// </value> |
| | | 24 | | protected override int BufferCapacity |
| | | 25 | | { |
| | | 26 | | get |
| | 131 | 27 | | { |
| | 131 | 28 | | var capacity = base.BufferCapacity; |
| | 131 | 29 | | capacity += 4; // Handle length |
| | 131 | 30 | | capacity += Handle.Length; // Handle |
| | 131 | 31 | | return capacity; |
| | 131 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public SftpReadDirRequest(uint protocolVersion, uint requestId, byte[] handle, Action<SftpNameResponse> nameActi |
| | 140 | 36 | | : base(protocolVersion, requestId, statusAction) |
| | 140 | 37 | | { |
| | 140 | 38 | | Handle = handle; |
| | | 39 | | |
| | 140 | 40 | | _nameAction = nameAction; |
| | 140 | 41 | | } |
| | | 42 | | |
| | | 43 | | protected override void LoadData() |
| | 0 | 44 | | { |
| | 0 | 45 | | base.LoadData(); |
| | 0 | 46 | | Handle = ReadBinary(); |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | protected override void SaveData() |
| | 131 | 50 | | { |
| | 131 | 51 | | base.SaveData(); |
| | 131 | 52 | | WriteBinaryString(Handle); |
| | 131 | 53 | | } |
| | | 54 | | |
| | | 55 | | public override void Complete(SftpResponse response) |
| | 134 | 56 | | { |
| | 134 | 57 | | if (response is SftpNameResponse nameResponse) |
| | 117 | 58 | | { |
| | 117 | 59 | | _nameAction(nameResponse); |
| | 117 | 60 | | } |
| | | 61 | | else |
| | 17 | 62 | | { |
| | 17 | 63 | | base.Complete(response); |
| | 17 | 64 | | } |
| | 134 | 65 | | } |
| | | 66 | | } |
| | | 67 | | } |