SftpStatRequest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Text;
  3. using Renci.SshNet.Sftp.Responses;
  4. namespace Renci.SshNet.Sftp.Requests
  5. {
  6. internal class SftpStatRequest : SftpRequest
  7. {
  8. #if TUNING
  9. private byte[] _path;
  10. #endif
  11. public override SftpMessageTypes SftpMessageType
  12. {
  13. get { return SftpMessageTypes.Stat; }
  14. }
  15. #if TUNING
  16. public string Path
  17. {
  18. get { return Encoding.GetString(_path, 0, _path.Length); }
  19. private set { _path = Encoding.GetBytes(value); }
  20. }
  21. #else
  22. public string Path { 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; // Path length
  38. capacity += _path.Length; // Path
  39. return capacity;
  40. }
  41. }
  42. #endif
  43. public SftpStatRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpAttrsResponse> attrsAction, Action<SftpStatusResponse> statusAction)
  44. : base(protocolVersion, requestId, statusAction)
  45. {
  46. this.Encoding = encoding;
  47. this.Path = path;
  48. this.SetAction(attrsAction);
  49. }
  50. protected override void LoadData()
  51. {
  52. base.LoadData();
  53. #if TUNING
  54. _path = ReadBinary();
  55. #else
  56. this.Path = this.ReadString(this.Encoding);
  57. #endif
  58. }
  59. protected override void SaveData()
  60. {
  61. base.SaveData();
  62. #if TUNING
  63. WriteBinaryString(_path);
  64. #else
  65. this.Write(this.Path, this.Encoding);
  66. #endif
  67. }
  68. }
  69. }