| | | 1 | | using System; |
| | | 2 | | using System.Text; |
| | | 3 | | |
| | | 4 | | using Renci.SshNet.Sftp.Responses; |
| | | 5 | | |
| | | 6 | | namespace Renci.SshNet.Sftp.Requests |
| | | 7 | | { |
| | | 8 | | internal sealed class SftpOpenDirRequest : SftpRequest |
| | | 9 | | { |
| | | 10 | | private readonly Action<SftpHandleResponse> _handleAction; |
| | | 11 | | private byte[] _path; |
| | | 12 | | |
| | | 13 | | public override SftpMessageTypes SftpMessageType |
| | | 14 | | { |
| | 132 | 15 | | get { return SftpMessageTypes.OpenDir; } |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | public string Path |
| | | 19 | | { |
| | 9 | 20 | | get { return Encoding.GetString(_path, 0, _path.Length); } |
| | 150 | 21 | | private set { _path = Encoding.GetBytes(value); } |
| | | 22 | | } |
| | | 23 | | |
| | 106 | 24 | | public Encoding Encoding { get; private set; } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the size of the message in bytes. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <value> |
| | | 30 | | /// The size of the messages in bytes. |
| | | 31 | | /// </value> |
| | | 32 | | protected override int BufferCapacity |
| | | 33 | | { |
| | | 34 | | get |
| | 41 | 35 | | { |
| | 41 | 36 | | var capacity = base.BufferCapacity; |
| | 41 | 37 | | capacity += 4; // Path length |
| | 41 | 38 | | capacity += _path.Length; // Path |
| | 41 | 39 | | return capacity; |
| | 41 | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public SftpOpenDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpHandl |
| | 50 | 44 | | : base(protocolVersion, requestId, statusAction) |
| | 50 | 45 | | { |
| | 50 | 46 | | Encoding = encoding; |
| | 50 | 47 | | Path = path; |
| | | 48 | | |
| | 50 | 49 | | _handleAction = handleAction; |
| | 50 | 50 | | } |
| | | 51 | | |
| | | 52 | | protected override void LoadData() |
| | 0 | 53 | | { |
| | 0 | 54 | | base.LoadData(); |
| | | 55 | | |
| | 0 | 56 | | _path = ReadBinary(); |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | protected override void SaveData() |
| | 41 | 60 | | { |
| | 41 | 61 | | base.SaveData(); |
| | | 62 | | |
| | 41 | 63 | | WriteBinaryString(_path); |
| | 41 | 64 | | } |
| | | 65 | | |
| | | 66 | | public override void Complete(SftpResponse response) |
| | 44 | 67 | | { |
| | 44 | 68 | | if (response is SftpHandleResponse handleResponse) |
| | 32 | 69 | | { |
| | 32 | 70 | | _handleAction(handleResponse); |
| | 32 | 71 | | } |
| | | 72 | | else |
| | 12 | 73 | | { |
| | 12 | 74 | | base.Complete(response); |
| | 12 | 75 | | } |
| | 44 | 76 | | } |
| | | 77 | | } |
| | | 78 | | } |