SftpRemoveRequest.cs 1.9 KB

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