SftpRealPathRequest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Text;
  3. using Renci.SshNet.Sftp.Responses;
  4. namespace Renci.SshNet.Sftp.Requests
  5. {
  6. internal class SftpRealPathRequest : SftpRequest
  7. {
  8. #if TUNING
  9. private byte[] _path;
  10. #endif
  11. public override SftpMessageTypes SftpMessageType
  12. {
  13. get { return SftpMessageTypes.RealPath; }
  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 SftpRealPathRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpNameResponse> nameAction, Action<SftpStatusResponse> statusAction)
  44. : base(protocolVersion, requestId, statusAction)
  45. {
  46. if (nameAction == null)
  47. throw new ArgumentNullException("nameAction");
  48. if (statusAction == null)
  49. throw new ArgumentNullException("statusAction");
  50. this.Encoding = encoding;
  51. this.Path = path;
  52. this.SetAction(nameAction);
  53. }
  54. protected override void SaveData()
  55. {
  56. base.SaveData();
  57. #if TUNING
  58. WriteBinaryString(_path);
  59. #else
  60. this.Write(this.Path, this.Encoding);
  61. #endif
  62. }
  63. }
  64. }