| | | 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 SftpMkDirRequest : SftpRequest |
| | | 8 | | { |
| | | 9 | | private byte[] _path; |
| | | 10 | | private byte[] _attributesBytes; |
| | | 11 | | |
| | | 12 | | public override SftpMessageTypes SftpMessageType |
| | | 13 | | { |
| | 30129 | 14 | | get { return SftpMessageTypes.MkDir; } |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | public string Path |
| | | 18 | | { |
| | 9 | 19 | | get { return Encoding.GetString(_path, 0, _path.Length); } |
| | 30138 | 20 | | private set { _path = Encoding.GetBytes(value); } |
| | | 21 | | } |
| | | 22 | | |
| | 20098 | 23 | | public Encoding Encoding { get; private set; } |
| | | 24 | | |
| | 20086 | 25 | | private SftpFileAttributes Attributes { get; set; } |
| | | 26 | | |
| | | 27 | | private byte[] AttributesBytes |
| | | 28 | | { |
| | | 29 | | get |
| | 20080 | 30 | | { |
| | 20080 | 31 | | _attributesBytes ??= Attributes.GetBytes(); |
| | | 32 | | |
| | 20080 | 33 | | return _attributesBytes; |
| | 20080 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the size of the message in bytes. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <value> |
| | | 41 | | /// The size of the messages in bytes. |
| | | 42 | | /// </value> |
| | | 43 | | protected override int BufferCapacity |
| | | 44 | | { |
| | | 45 | | get |
| | 10040 | 46 | | { |
| | 10040 | 47 | | var capacity = base.BufferCapacity; |
| | 10040 | 48 | | capacity += 4; // Path length |
| | 10040 | 49 | | capacity += _path.Length; // Path |
| | 10040 | 50 | | capacity += AttributesBytes.Length; // Attributes |
| | 10040 | 51 | | return capacity; |
| | 10040 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public SftpMkDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpStatusR |
| | 10046 | 56 | | : this(protocolVersion, requestId, path, encoding, SftpFileAttributes.Empty, statusAction) |
| | 10046 | 57 | | { |
| | 10046 | 58 | | } |
| | | 59 | | |
| | | 60 | | private SftpMkDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, SftpFileAttribute |
| | 10046 | 61 | | : base(protocolVersion, requestId, statusAction) |
| | 10046 | 62 | | { |
| | 10046 | 63 | | Encoding = encoding; |
| | 10046 | 64 | | Path = path; |
| | 10046 | 65 | | Attributes = attributes; |
| | 10046 | 66 | | } |
| | | 67 | | |
| | | 68 | | protected override void LoadData() |
| | 0 | 69 | | { |
| | 0 | 70 | | base.LoadData(); |
| | 0 | 71 | | _path = ReadBinary(); |
| | 0 | 72 | | Attributes = ReadAttributes(); |
| | 0 | 73 | | } |
| | | 74 | | |
| | | 75 | | protected override void SaveData() |
| | 10040 | 76 | | { |
| | 10040 | 77 | | base.SaveData(); |
| | 10040 | 78 | | WriteBinaryString(_path); |
| | 10040 | 79 | | Write(AttributesBytes); |
| | 10040 | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |