| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Sftp.Responses; |
| | | 4 | | |
| | | 5 | | namespace Renci.SshNet.Sftp.Requests |
| | | 6 | | { |
| | | 7 | | internal sealed class SftpLinkRequest : SftpRequest |
| | | 8 | | { |
| | | 9 | | private byte[] _newLinkPath; |
| | | 10 | | private byte[] _existingPath; |
| | | 11 | | |
| | | 12 | | public override SftpMessageTypes SftpMessageType |
| | | 13 | | { |
| | 18 | 14 | | get { return SftpMessageTypes.Link; } |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | public string NewLinkPath |
| | | 18 | | { |
| | 18 | 19 | | get { return Utf8.GetString(_newLinkPath, 0, _newLinkPath.Length); } |
| | 36 | 20 | | private set { _newLinkPath = Utf8.GetBytes(value); } |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | public string ExistingPath |
| | | 24 | | { |
| | 18 | 25 | | get { return Utf8.GetString(_existingPath, 0, _existingPath.Length); } |
| | 36 | 26 | | private set { _existingPath = Utf8.GetBytes(value); } |
| | | 27 | | } |
| | | 28 | | |
| | 21 | 29 | | public bool IsSymLink { get; private set; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets the size of the message in bytes. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <value> |
| | | 35 | | /// The size of the messages in bytes. |
| | | 36 | | /// </value> |
| | | 37 | | protected override int BufferCapacity |
| | | 38 | | { |
| | | 39 | | get |
| | 3 | 40 | | { |
| | 3 | 41 | | var capacity = base.BufferCapacity; |
| | 3 | 42 | | capacity += 4; // NewLinkPath length |
| | 3 | 43 | | capacity += NewLinkPath.Length; // NewLinkPath |
| | 3 | 44 | | capacity += 4; // ExistingPath length |
| | 3 | 45 | | capacity += ExistingPath.Length; // ExistingPath |
| | 3 | 46 | | capacity += 1; // IsSymLink |
| | 3 | 47 | | return capacity; |
| | 3 | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Initializes a new instance of the <see cref="SftpLinkRequest" /> class. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="protocolVersion">The protocol version.</param> |
| | | 55 | | /// <param name="requestId">The request id.</param> |
| | | 56 | | /// <param name="newLinkPath">Specifies the path name of the new link to create.</param> |
| | | 57 | | /// <param name="existingPath">Specifies the path of a target object to which the newly created link will refer. |
| | | 58 | | /// <param name="isSymLink">if set to <see langword="false"/> the link should be a hard link, or a second direct |
| | | 59 | | /// <param name="statusAction">The status action.</param> |
| | | 60 | | public SftpLinkRequest(uint protocolVersion, uint requestId, string newLinkPath, string existingPath, bool isSym |
| | 12 | 61 | | : base(protocolVersion, requestId, statusAction) |
| | 12 | 62 | | { |
| | 12 | 63 | | NewLinkPath = newLinkPath; |
| | 12 | 64 | | ExistingPath = existingPath; |
| | 12 | 65 | | IsSymLink = isSymLink; |
| | 12 | 66 | | } |
| | | 67 | | |
| | | 68 | | protected override void LoadData() |
| | 0 | 69 | | { |
| | 0 | 70 | | base.LoadData(); |
| | | 71 | | |
| | 0 | 72 | | _newLinkPath = ReadBinary(); |
| | 0 | 73 | | _existingPath = ReadBinary(); |
| | 0 | 74 | | IsSymLink = ReadBoolean(); |
| | 0 | 75 | | } |
| | | 76 | | |
| | | 77 | | protected override void SaveData() |
| | 3 | 78 | | { |
| | 3 | 79 | | base.SaveData(); |
| | | 80 | | |
| | 3 | 81 | | WriteBinaryString(_newLinkPath); |
| | 3 | 82 | | WriteBinaryString(_existingPath); |
| | 3 | 83 | | Write(IsSymLink); |
| | 3 | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |