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