2
0

SftpWriteRequest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using Renci.SshNet.Sftp.Responses;
  3. namespace Renci.SshNet.Sftp.Requests
  4. {
  5. internal class SftpWriteRequest : SftpRequest
  6. {
  7. public override SftpMessageTypes SftpMessageType
  8. {
  9. get { return SftpMessageTypes.Write; }
  10. }
  11. public byte[] Handle { get; private set; }
  12. public UInt64 Offset { get; private set; }
  13. public byte[] Data { get; private set; }
  14. #if TUNING
  15. public int Length { get; private set; }
  16. protected override int BufferCapacity
  17. {
  18. get
  19. {
  20. var capacity = base.BufferCapacity;
  21. capacity += 4; // Handle length
  22. capacity += Handle.Length; // Handle
  23. capacity += 8; // Offset length
  24. capacity += 4; // Data length
  25. capacity += Length; // Data
  26. return capacity;
  27. }
  28. }
  29. #endif
  30. public SftpWriteRequest(uint protocolVersion,
  31. uint requestId,
  32. byte[] handle,
  33. UInt64 offset,
  34. byte[] data,
  35. #if TUNING
  36. int length,
  37. #endif
  38. Action<SftpStatusResponse> statusAction)
  39. : base(protocolVersion, requestId, statusAction)
  40. {
  41. this.Handle = handle;
  42. this.Offset = offset;
  43. this.Data = data;
  44. #if TUNING
  45. this.Length = length;
  46. #endif
  47. }
  48. protected override void LoadData()
  49. {
  50. base.LoadData();
  51. #if TUNING
  52. this.Handle = this.ReadBinary();
  53. #else
  54. this.Handle = this.ReadBinaryString();
  55. #endif
  56. this.Offset = this.ReadUInt64();
  57. #if TUNING
  58. this.Data = this.ReadBinary();
  59. #else
  60. this.Data = this.ReadBinaryString();
  61. #endif
  62. #if TUNING
  63. this.Length = this.Data.Length;
  64. #endif
  65. }
  66. protected override void SaveData()
  67. {
  68. base.SaveData();
  69. this.WriteBinaryString(this.Handle);
  70. this.Write(this.Offset);
  71. #if TUNING
  72. this.WriteBinary(this.Data, 0, Length);
  73. #else
  74. this.WriteBinaryString(this.Data);
  75. #endif
  76. }
  77. }
  78. }