| | | 1 | | using System; |
| | | 2 | | using System.Text; |
| | | 3 | | using Renci.SshNet.Sftp.Responses; |
| | | 4 | | |
| | | 5 | | namespace Renci.SshNet.Sftp.Requests |
| | | 6 | | { |
| | | 7 | | internal sealed class SftpOpenRequest : SftpRequest |
| | | 8 | | { |
| | | 9 | | private readonly Action<SftpHandleResponse> _handleAction; |
| | | 10 | | private byte[] _fileName; |
| | | 11 | | private byte[] _attributes; |
| | | 12 | | |
| | | 13 | | public override SftpMessageTypes SftpMessageType |
| | | 14 | | { |
| | 1305 | 15 | | get { return SftpMessageTypes.Open; } |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | public string Filename |
| | | 19 | | { |
| | 9 | 20 | | get { return Encoding.GetString(_fileName, 0, _fileName.Length); } |
| | 1323 | 21 | | private set { _fileName = Encoding.GetBytes(value); } |
| | | 22 | | } |
| | | 23 | | |
| | 432 | 24 | | public Flags Flags { get; } |
| | | 25 | | |
| | | 26 | | public SftpFileAttributes Attributes |
| | | 27 | | { |
| | 0 | 28 | | get { return SftpFileAttributes.FromBytes(_attributes); } |
| | 1323 | 29 | | private set { _attributes = value.GetBytes(); } |
| | | 30 | | } |
| | | 31 | | |
| | 447 | 32 | | public Encoding Encoding { get; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the size of the message in bytes. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <value> |
| | | 38 | | /// The size of the messages in bytes. |
| | | 39 | | /// </value> |
| | | 40 | | protected override int BufferCapacity |
| | | 41 | | { |
| | | 42 | | get |
| | 432 | 43 | | { |
| | 432 | 44 | | var capacity = base.BufferCapacity; |
| | 432 | 45 | | capacity += 4; // FileName length |
| | 432 | 46 | | capacity += _fileName.Length; // FileName |
| | 432 | 47 | | capacity += 4; // Flags |
| | 432 | 48 | | capacity += _attributes.Length; // Attributes |
| | 432 | 49 | | return capacity; |
| | 432 | 50 | | } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public SftpOpenRequest(uint protocolVersion, uint requestId, string fileName, Encoding encoding, Flags flags, Ac |
| | 441 | 54 | | : this(protocolVersion, requestId, fileName, encoding, flags, SftpFileAttributes.Empty, handleAction, status |
| | 441 | 55 | | { |
| | 441 | 56 | | } |
| | | 57 | | |
| | | 58 | | private SftpOpenRequest(uint protocolVersion, uint requestId, string fileName, Encoding encoding, Flags flags, S |
| | 441 | 59 | | : base(protocolVersion, requestId, statusAction) |
| | 441 | 60 | | { |
| | 441 | 61 | | Encoding = encoding; |
| | 441 | 62 | | Filename = fileName; |
| | 441 | 63 | | Flags = flags; |
| | 441 | 64 | | Attributes = attributes; |
| | | 65 | | |
| | 441 | 66 | | _handleAction = handleAction; |
| | 441 | 67 | | } |
| | | 68 | | |
| | | 69 | | protected override void LoadData() |
| | 0 | 70 | | { |
| | 0 | 71 | | base.LoadData(); |
| | 0 | 72 | | throw new NotSupportedException(); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | protected override void SaveData() |
| | 432 | 76 | | { |
| | 432 | 77 | | base.SaveData(); |
| | | 78 | | |
| | 432 | 79 | | WriteBinaryString(_fileName); |
| | 432 | 80 | | Write((uint) Flags); |
| | 432 | 81 | | Write(_attributes); |
| | 432 | 82 | | } |
| | | 83 | | |
| | | 84 | | public override void Complete(SftpResponse response) |
| | 423 | 85 | | { |
| | 423 | 86 | | if (response is SftpHandleResponse handleResponse) |
| | 376 | 87 | | { |
| | 376 | 88 | | _handleAction(handleResponse); |
| | 376 | 89 | | } |
| | | 90 | | else |
| | 47 | 91 | | { |
| | 47 | 92 | | base.Complete(response); |
| | 47 | 93 | | } |
| | 423 | 94 | | } |
| | | 95 | | } |
| | | 96 | | } |