| | | 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 PosixRenameRequest : SftpExtendedRequest |
| | | 9 | | { |
| | | 10 | | private byte[] _oldPath; |
| | | 11 | | private byte[] _newPath; |
| | | 12 | | |
| | | 13 | | public string OldPath |
| | | 14 | | { |
| | 9 | 15 | | get { return Encoding.GetString(_oldPath, 0, _oldPath.Length); } |
| | 27 | 16 | | private set { _oldPath = Encoding.GetBytes(value); } |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | public string NewPath |
| | | 20 | | { |
| | 9 | 21 | | get { return Encoding.GetString(_newPath, 0, _newPath.Length); } |
| | 27 | 22 | | private set { _newPath = Encoding.GetBytes(value); } |
| | | 23 | | } |
| | | 24 | | |
| | 27 | 25 | | public Encoding Encoding { get; } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets the size of the message in bytes. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <value> |
| | | 31 | | /// The size of the messages in bytes. |
| | | 32 | | /// </value> |
| | | 33 | | protected override int BufferCapacity |
| | | 34 | | { |
| | | 35 | | get |
| | 3 | 36 | | { |
| | 3 | 37 | | var capacity = base.BufferCapacity; |
| | 3 | 38 | | capacity += 4; // OldPath length |
| | 3 | 39 | | capacity += _oldPath.Length; // OldPath |
| | 3 | 40 | | capacity += 4; // NewPath length |
| | 3 | 41 | | capacity += _newPath.Length; // NewPath |
| | 3 | 42 | | return capacity; |
| | 3 | 43 | | } |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public PosixRenameRequest(uint protocolVersion, uint requestId, string oldPath, string newPath, Encoding encodin |
| | 9 | 47 | | : base(protocolVersion, requestId, statusAction, "posix-rename@openssh.com") |
| | 9 | 48 | | { |
| | 9 | 49 | | Encoding = encoding; |
| | 9 | 50 | | OldPath = oldPath; |
| | 9 | 51 | | NewPath = newPath; |
| | 9 | 52 | | } |
| | | 53 | | |
| | | 54 | | protected override void SaveData() |
| | 3 | 55 | | { |
| | 3 | 56 | | base.SaveData(); |
| | | 57 | | |
| | 3 | 58 | | WriteBinaryString(_oldPath); |
| | 3 | 59 | | WriteBinaryString(_newPath); |
| | 3 | 60 | | } |
| | | 61 | | } |
| | | 62 | | } |