2
0

SftpRenameRequest.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Text;
  3. using Renci.SshNet.Sftp.Responses;
  4. namespace Renci.SshNet.Sftp.Requests
  5. {
  6. internal class SftpRenameRequest : SftpRequest
  7. {
  8. #if TUNING
  9. private byte[] _oldPath;
  10. private byte[] _newPath;
  11. #endif
  12. public override SftpMessageTypes SftpMessageType
  13. {
  14. get { return SftpMessageTypes.Rename; }
  15. }
  16. #if TUNING
  17. public string OldPath
  18. {
  19. get { return Encoding.GetString(_oldPath, 0, _oldPath.Length); }
  20. private set { _oldPath = Encoding.GetBytes(value); }
  21. }
  22. #else
  23. public string OldPath { get; private set; }
  24. #endif
  25. #if TUNING
  26. public string NewPath
  27. {
  28. get { return Encoding.GetString(_newPath, 0, _newPath.Length); }
  29. private set { _newPath = Encoding.GetBytes(value); }
  30. }
  31. #else
  32. public string NewPath { get; private set; }
  33. #endif
  34. public Encoding Encoding { get; private set; }
  35. #if TUNING
  36. /// <summary>
  37. /// Gets the size of the message in bytes.
  38. /// </summary>
  39. /// <value>
  40. /// The size of the messages in bytes.
  41. /// </value>
  42. protected override int BufferCapacity
  43. {
  44. get
  45. {
  46. var capacity = base.BufferCapacity;
  47. capacity += 4; // OldPath length
  48. capacity += _oldPath.Length; // OldPath
  49. capacity += 4; // NewPath length
  50. capacity += _newPath.Length; // NewPath
  51. return capacity;
  52. }
  53. }
  54. #endif
  55. public SftpRenameRequest(uint protocolVersion, uint requestId, string oldPath, string newPath, Encoding encoding, Action<SftpStatusResponse> statusAction)
  56. : base(protocolVersion, requestId, statusAction)
  57. {
  58. this.Encoding = encoding;
  59. this.OldPath = oldPath;
  60. this.NewPath = newPath;
  61. }
  62. protected override void LoadData()
  63. {
  64. base.LoadData();
  65. #if TUNING
  66. _oldPath = ReadBinary();
  67. _newPath = ReadBinary();
  68. #else
  69. this.OldPath = this.ReadString(this.Encoding);
  70. this.NewPath = this.ReadString(this.Encoding);
  71. #endif
  72. }
  73. protected override void SaveData()
  74. {
  75. base.SaveData();
  76. #if TUNING
  77. WriteBinaryString(_oldPath);
  78. WriteBinaryString(_newPath);
  79. #else
  80. this.Write(this.OldPath, this.Encoding);
  81. this.Write(this.NewPath, this.Encoding);
  82. #endif
  83. }
  84. }
  85. }