| | | 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 SftpRenameRequest : SftpRequest |
| | | 8 | | { |
| | | 9 | | private byte[] _oldPath; |
| | | 10 | | private byte[] _newPath; |
| | | 11 | | |
| | | 12 | | public override SftpMessageTypes SftpMessageType |
| | | 13 | | { |
| | 27 | 14 | | get { return SftpMessageTypes.Rename; } |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | public string OldPath |
| | | 18 | | { |
| | 9 | 19 | | get { return Encoding.GetString(_oldPath, 0, _oldPath.Length); } |
| | 36 | 20 | | private set { _oldPath = Encoding.GetBytes(value); } |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | public string NewPath |
| | | 24 | | { |
| | 9 | 25 | | get { return Encoding.GetString(_newPath, 0, _newPath.Length); } |
| | 36 | 26 | | private set { _newPath = Encoding.GetBytes(value); } |
| | | 27 | | } |
| | | 28 | | |
| | 45 | 29 | | public Encoding Encoding { 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 |
| | 6 | 40 | | { |
| | 6 | 41 | | var capacity = base.BufferCapacity; |
| | 6 | 42 | | capacity += 4; // OldPath length |
| | 6 | 43 | | capacity += _oldPath.Length; // OldPath |
| | 6 | 44 | | capacity += 4; // NewPath length |
| | 6 | 45 | | capacity += _newPath.Length; // NewPath |
| | 6 | 46 | | return capacity; |
| | 6 | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public SftpRenameRequest(uint protocolVersion, uint requestId, string oldPath, string newPath, Encoding encoding |
| | 12 | 51 | | : base(protocolVersion, requestId, statusAction) |
| | 12 | 52 | | { |
| | 12 | 53 | | Encoding = encoding; |
| | 12 | 54 | | OldPath = oldPath; |
| | 12 | 55 | | NewPath = newPath; |
| | 12 | 56 | | } |
| | | 57 | | |
| | | 58 | | protected override void LoadData() |
| | 0 | 59 | | { |
| | 0 | 60 | | base.LoadData(); |
| | | 61 | | |
| | 0 | 62 | | _oldPath = ReadBinary(); |
| | 0 | 63 | | _newPath = ReadBinary(); |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | protected override void SaveData() |
| | 6 | 67 | | { |
| | 6 | 68 | | base.SaveData(); |
| | | 69 | | |
| | 6 | 70 | | WriteBinaryString(_oldPath); |
| | 6 | 71 | | WriteBinaryString(_newPath); |
| | 6 | 72 | | } |
| | | 73 | | } |
| | | 74 | | } |