-
-
Notifications
You must be signed in to change notification settings - Fork 978
Expand file tree
/
Copy pathScpClient.cs
More file actions
630 lines (547 loc) · 27.7 KB
/
ScpClient.cs
File metadata and controls
630 lines (547 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
using System;
using Renci.SshNet.Channels;
using System.IO;
using Renci.SshNet.Common;
using System.Text.RegularExpressions;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Collections.Generic;
#if FEATURE_TPL
using System.Threading;
#endif
namespace Renci.SshNet
{
/// <summary>
/// Provides SCP client functionality.
/// </summary>
/// <remarks>
/// <para>
/// More information on the SCP protocol is available here:
/// https://github.com/net-ssh/net-scp/blob/master/lib/net/scp.rb
/// </para>
/// <para>
/// Known issues in OpenSSH:
/// <list type="bullet">
/// <item>
/// <description>Recursive download (-prf) does not deal well with specific UTF-8 and newline characters.</description>
/// <description>Recursive update does not support empty path for uploading to home directory.</description>
/// </item>
/// </list>
/// </para>
/// </remarks>
public partial class ScpClient : BaseClient
{
private static readonly Regex FileInfoRe = new Regex(@"C(?<mode>\d{4}) (?<length>\d+) (?<filename>.+)");
private static readonly byte[] SuccessConfirmationCode = {0};
private static readonly byte[] ErrorConfirmationCode = { 1 };
private IRemotePathTransformation _remotePathTransformation;
/// <summary>
/// Gets or sets the operation timeout.
/// </summary>
/// <value>
/// The timeout to wait until an operation completes. The default value is negative
/// one (-1) milliseconds, which indicates an infinite time-out period.
/// </value>
public TimeSpan OperationTimeout { get; set; }
/// <summary>
/// Gets or sets the size of the buffer.
/// </summary>
/// <value>
/// The size of the buffer. The default buffer size is 16384 bytes.
/// </value>
public uint BufferSize { get; set; }
/// <summary>
/// Gets or sets the transformation to apply to remote paths.
/// </summary>
/// <value>
/// The transformation to apply to remote paths. The default is <see cref="SshNet.RemotePathTransformation.DoubleQuote"/>.
/// </value>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
/// <remarks>
/// <para>
/// This transformation is applied to the remote file or directory path that is passed to the
/// <c>scp</c> command.
/// </para>
/// <para>
/// See <see cref="SshNet.RemotePathTransformation"/> for the transformations that are supplied
/// out-of-the-box with SSH.NET.
/// </para>
/// </remarks>
public IRemotePathTransformation RemotePathTransformation
{
get { return _remotePathTransformation; }
set
{
if (value == null)
throw new ArgumentNullException("value");
_remotePathTransformation = value;
}
}
/// <summary>
/// Occurs when downloading file.
/// </summary>
public event EventHandler<ScpDownloadEventArgs> Downloading;
/// <summary>
/// Occurs when uploading file.
/// </summary>
public event EventHandler<ScpUploadEventArgs> Uploading;
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
/// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <c>null</c>.</exception>
public ScpClient(ConnectionInfo connectionInfo)
: this(connectionInfo, false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="port">Connection port.</param>
/// <param name="username">Authentication username.</param>
/// <param name="password">Authentication password.</param>
/// <exception cref="ArgumentNullException"><paramref name="password"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
public ScpClient(string host, int port, string username, string password)
: this(new PasswordConnectionInfo(host, port, username, password), true)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="username">Authentication username.</param>
/// <param name="password">Authentication password.</param>
/// <exception cref="ArgumentNullException"><paramref name="password"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception>
public ScpClient(string host, string username, string password)
: this(host, ConnectionInfo.DefaultPort, username, password)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="port">Connection port.</param>
/// <param name="username">Authentication username.</param>
/// <param name="keyFiles">Authentication private key file(s) .</param>
/// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
public ScpClient(string host, int port, string username, params PrivateKeyFile[] keyFiles)
: this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), true)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="username">Authentication username.</param>
/// <param name="keyFiles">Authentication private key file(s) .</param>
/// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception>
public ScpClient(string host, string username, params PrivateKeyFile[] keyFiles)
: this(host, ConnectionInfo.DefaultPort, username, keyFiles)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
/// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
/// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <c>null</c>.</exception>
/// <remarks>
/// If <paramref name="ownsConnectionInfo"/> is <c>true</c>, then the
/// connection info will be disposed when this instance is disposed.
/// </remarks>
private ScpClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)
: this(connectionInfo, ownsConnectionInfo, new ServiceFactory())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ScpClient"/> class.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
/// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
/// <param name="serviceFactory">The factory to use for creating new services.</param>
/// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="serviceFactory"/> is <c>null</c>.</exception>
/// <remarks>
/// If <paramref name="ownsConnectionInfo"/> is <c>true</c>, then the
/// connection info will be disposed when this instance is disposed.
/// </remarks>
internal ScpClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory)
: base(connectionInfo, ownsConnectionInfo, serviceFactory)
{
OperationTimeout = SshNet.Session.InfiniteTimeSpan;
BufferSize = 1024 * 16;
_remotePathTransformation = serviceFactory.CreateRemotePathDoubleQuoteTransformation();
}
#endregion
#if FEATURE_TPL
/// <summary>
/// Uploads the specified stream to the remote host.
/// </summary>
/// <param name="source">The <see cref="Stream"/> to upload.</param>
/// <param name="path">A relative or absolute path for the remote file.</param>
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length <see cref="string"/>.</exception>
/// <exception cref="ScpException">A directory with the specified path exists on the remote host.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
public void Upload(Stream source, string path)
{
Upload(source, path, CancellationToken.None);
}
#endif
#if FEATURE_TPL
/// <summary>
/// Uploads the specified stream to the remote host.
/// </summary>
/// <param name="source">The <see cref="Stream"/> to upload.</param>
/// <param name="path">A relative or absolute path for the remote file.</param>
/// <param name="cancellationToken">cancellation token</param>
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length <see cref="string"/>.</exception>
/// <exception cref="ScpException">A directory with the specified path exists on the remote host.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
/// <exception cref="OperationCanceledException">Download cancelled exception</exception>
public void Upload(Stream source, string path,CancellationToken cancellationToken )
{
try
{
var posixPath = PosixPath.CreateAbsoluteOrRelativeFilePath(path);
using (var input = ServiceFactory.CreatePipeStream())
using (var channel = Session.CreateChannelSession())
using (cancellationToken.Register(() => { channel.Dispose(); input.Dispose(); }))
{
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
channel.Open();
// Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
// that we expect the target to be a directory.
if (!channel.SendExecRequest(string.Format("scp -t -d {0}",
_remotePathTransformation.Transform(posixPath.Directory))))
{
throw SecureExecutionRequestRejectedException();
}
CheckReturnCode(input);
UploadFileModeAndName(channel, input, source.Length, posixPath.File);
UploadFileContent(channel, input, source, posixPath.File);
}
}
catch(Exception)
{
if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException();
else
throw;
}
}
#else
/// <summary>
/// Uploads the specified stream to the remote host.
/// </summary>
/// <param name="source">The <see cref="Stream"/> to upload.</param>
/// <param name="path">A relative or absolute path for the remote file.</param>
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length <see cref="string"/>.</exception>
/// <exception cref="ScpException">A directory with the specified path exists on the remote host.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
public void Upload(Stream source, string path)
{
var posixPath = PosixPath.CreateAbsoluteOrRelativeFilePath(path);
using (var input = ServiceFactory.CreatePipeStream())
using (var channel = Session.CreateChannelSession())
{
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
channel.Open();
// Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
// that we expect the target to be a directory.
if (!channel.SendExecRequest(string.Format("scp -t -d {0}", _remotePathTransformation.Transform(posixPath.Directory))))
{
throw SecureExecutionRequestRejectedException();
}
CheckReturnCode(input);
UploadFileModeAndName(channel, input, source.Length, posixPath.File);
UploadFileContent(channel, input, source, posixPath.File);
}
}
#endif
#if FEATURE_TPL
/// <summary>
/// Downloads the specified file from the remote host to the stream.
/// </summary>
/// <param name="filename">A relative or absolute path for the remote file.</param>
/// <param name="destination">The <see cref="Stream"/> to download the remote file to.</param>
/// <exception cref="ArgumentException"><paramref name="filename"/> is <c>null</c> or contains only whitespace characters.</exception>
/// <exception cref="ArgumentNullException"><paramref name="destination"/> is <c>null</c>.</exception>
/// <exception cref="ScpException"><paramref name="filename"/> exists on the remote host, and is not a regular file.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
public void Download(string filename, Stream destination)
{
Download(filename,destination,CancellationToken.None);
}
#endif
#if FEATURE_TPL
/// <summary>
/// Downloads the specified file from the remote host to the stream.
/// </summary>
/// <param name="filename">A relative or absolute path for the remote file.</param>
/// <param name="destination">The <see cref="Stream"/> to download the remote file to.</param>
/// <param name="cancellationToken">cancellation token</param>
/// <exception cref="ArgumentException"><paramref name="filename"/> is <c>null</c> or contains only whitespace characters.</exception>
/// <exception cref="ArgumentNullException"><paramref name="destination"/> is <c>null</c>.</exception>
/// <exception cref="ScpException"><paramref name="filename"/> exists on the remote host, and is not a regular file.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
/// <exception cref="OperationCanceledException">Download cancelled exception</exception>
public void Download(string filename, Stream destination, CancellationToken cancellationToken)
{
if (filename.IsNullOrWhiteSpace())
throw new ArgumentException("filename");
if (destination == null)
throw new ArgumentNullException("destination");
try
{
using (var input = ServiceFactory.CreatePipeStream())
using (var channel = Session.CreateChannelSession())
using (cancellationToken.Register(() =>
{
channel.Dispose();
input.Dispose();
}))
{
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
channel.Open();
// Send channel command request
if (!channel.SendExecRequest(string.Format("scp -f {0}",
_remotePathTransformation.Transform(filename))))
{
throw SecureExecutionRequestRejectedException();
}
SendSuccessConfirmation(channel); // Send reply
var message = ReadString(input);
var match = FileInfoRe.Match(message);
if (match.Success)
{
// Read file
SendSuccessConfirmation(channel); // Send reply
var length = long.Parse(match.Result("${length}"));
var fileName = match.Result("${filename}");
InternalDownload(channel, input, destination, fileName, length);
}
else
{
SendErrorConfirmation(channel,
string.Format("\"{0}\" is not valid protocol message.", message));
}
}
}
catch (Exception)
{
if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException();
else
throw;
}
}
#else
/// <summary>
/// Downloads the specified file from the remote host to the stream.
/// </summary>
/// <param name="filename">A relative or absolute path for the remote file.</param>
/// <param name="destination">The <see cref="Stream"/> to download the remote file to.</param>
/// <exception cref="ArgumentException"><paramref name="filename"/> is <c>null</c> or contains only whitespace characters.</exception>
/// <exception cref="ArgumentNullException"><paramref name="destination"/> is <c>null</c>.</exception>
/// <exception cref="ScpException"><paramref name="filename"/> exists on the remote host, and is not a regular file.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
public void Download(string filename, Stream destination)
{
if (filename.IsNullOrWhiteSpace())
throw new ArgumentException("filename");
if (destination == null)
throw new ArgumentNullException("destination");
using (var input = ServiceFactory.CreatePipeStream())
using (var channel = Session.CreateChannelSession())
{
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
channel.Open();
// Send channel command request
if (!channel.SendExecRequest(string.Format("scp -f {0}", _remotePathTransformation.Transform(filename))))
{
throw SecureExecutionRequestRejectedException();
}
SendSuccessConfirmation(channel); // Send reply
var message = ReadString(input);
var match = FileInfoRe.Match(message);
if (match.Success)
{
// Read file
SendSuccessConfirmation(channel); // Send reply
var length = long.Parse(match.Result("${length}"));
var fileName = match.Result("${filename}");
InternalDownload(channel, input, destination, fileName, length);
}
else
{
SendErrorConfirmation(channel, string.Format("\"{0}\" is not valid protocol message.", message));
}
}
}
#endif
/// <summary>
/// Sets mode, size and name of file being upload.
/// </summary>
/// <param name="channel">The channel to perform the upload in.</param>
/// <param name="input">A <see cref="Stream"/> from which any feedback from the server can be read.</param>
/// <param name="fileSize">The size of the content to upload.</param>
/// <param name="serverFileName">The name of the file, without path, to which the content is to be uploaded.</param>
/// <remarks>
/// <para>
/// When the SCP transfer is already initiated for a file, a zero-length <see cref="string"/> should
/// be specified for <paramref name="serverFileName"/>. This prevents the server from uploading the
/// content to a file with path <c><file path>/<paramref name="serverFileName"/></c> if there's
/// already a directory with this path, and allows us to receive an error response.
/// </para>
/// </remarks>
private void UploadFileModeAndName(IChannelSession channel, Stream input, long fileSize, string serverFileName)
{
SendData(channel, string.Format("C0644 {0} {1}\n", fileSize, serverFileName));
CheckReturnCode(input);
}
/// <summary>
/// Uploads the content of a file.
/// </summary>
/// <param name="channel">The channel to perform the upload in.</param>
/// <param name="input">A <see cref="Stream"/> from which any feedback from the server can be read.</param>
/// <param name="source">The content to upload.</param>
/// <param name="remoteFileName">The name of the remote file, without path, to which the content is uploaded.</param>
/// <remarks>
/// <paramref name="remoteFileName"/> is only used for raising the <see cref="Uploading"/> event.
/// </remarks>
private void UploadFileContent(IChannelSession channel, Stream input, Stream source, string remoteFileName)
{
var totalLength = source.Length;
var buffer = new byte[BufferSize];
var read = source.Read(buffer, 0, buffer.Length);
long totalRead = 0;
while (read > 0)
{
SendData(channel, buffer, read);
totalRead += read;
RaiseUploadingEvent(remoteFileName, totalLength, totalRead);
read = source.Read(buffer, 0, buffer.Length);
}
SendSuccessConfirmation(channel);
CheckReturnCode(input);
}
private void InternalDownload(IChannel channel, Stream input, Stream output, string filename, long length)
{
var buffer = new byte[Math.Min(length, BufferSize)];
var needToRead = length;
do
{
var read = input.Read(buffer, 0, (int) Math.Min(needToRead, BufferSize));
output.Write(buffer, 0, read);
RaiseDownloadingEvent(filename, length, length - needToRead);
needToRead -= read;
}
while (needToRead > 0);
output.Flush();
// Raise one more time when file downloaded
RaiseDownloadingEvent(filename, length, length - needToRead);
// Send confirmation byte after last data byte was read
SendSuccessConfirmation(channel);
CheckReturnCode(input);
}
private void RaiseDownloadingEvent(string filename, long size, long downloaded)
{
if (Downloading != null)
{
Downloading(this, new ScpDownloadEventArgs(filename, size, downloaded));
}
}
private void RaiseUploadingEvent(string filename, long size, long uploaded)
{
if (Uploading != null)
{
Uploading(this, new ScpUploadEventArgs(filename, size, uploaded));
}
}
private static void SendSuccessConfirmation(IChannel channel)
{
SendData(channel, SuccessConfirmationCode);
}
private void SendErrorConfirmation(IChannel channel, string message)
{
SendData(channel, ErrorConfirmationCode);
SendData(channel, string.Concat(message, "\n"));
}
/// <summary>
/// Checks the return code.
/// </summary>
/// <param name="input">The output stream.</param>
private void CheckReturnCode(Stream input)
{
var b = ReadByte(input);
if (b > 0)
{
var errorText = ReadString(input);
throw new ScpException(errorText);
}
}
private void SendData(IChannel channel, string command)
{
channel.SendData(ConnectionInfo.Encoding.GetBytes(command));
}
private static void SendData(IChannel channel, byte[] buffer, int length)
{
channel.SendData(buffer, 0, length);
}
private static void SendData(IChannel channel, byte[] buffer)
{
channel.SendData(buffer);
}
private static int ReadByte(Stream stream)
{
var b = stream.ReadByte();
if (b == -1)
throw new SshException("Stream has been closed.");
return b;
}
/// <summary>
/// Read a LF-terminated string from the <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to read from.</param>
/// <returns>
/// The string without trailing LF.
/// </returns>
private string ReadString(Stream stream)
{
var hasError = false;
var buffer = new List<byte>();
var b = ReadByte(stream);
if (b == 1 || b == 2)
{
hasError = true;
b = ReadByte(stream);
}
while (b != SshNet.Session.LineFeed)
{
buffer.Add((byte) b);
b = ReadByte(stream);
}
var readBytes = buffer.ToArray();
if (hasError)
throw new ScpException(ConnectionInfo.Encoding.GetString(readBytes, 0, readBytes.Length));
return ConnectionInfo.Encoding.GetString(readBytes, 0, readBytes.Length);
}
private static SshException SecureExecutionRequestRejectedException()
{
throw new SshException("Secure copy execution request was rejected by the server. Please consult the server logs.");
}
}
}