|
|
@@ -10,6 +10,9 @@ using Renci.SshNet.Abstractions;
|
|
|
using Renci.SshNet.Common;
|
|
|
using Renci.SshNet.Sftp;
|
|
|
using System.Threading.Tasks;
|
|
|
+#if FEATURE_ASYNC_ENUMERABLE
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
+#endif
|
|
|
|
|
|
namespace Renci.SshNet
|
|
|
{
|
|
|
@@ -92,7 +95,7 @@ namespace Renci.SshNet
|
|
|
/// SSH_FXP_DATA protocol fields.
|
|
|
/// </para>
|
|
|
/// <para>
|
|
|
- /// The size of the each indivual SSH_FXP_DATA message is limited to the
|
|
|
+ /// The size of the each individual SSH_FXP_DATA message is limited to the
|
|
|
/// local maximum packet size of the channel, which is set to <c>64 KB</c>
|
|
|
/// for SSH.NET. However, the peer can limit this even further.
|
|
|
/// </para>
|
|
|
@@ -584,21 +587,22 @@ namespace Renci.SshNet
|
|
|
return InternalListDirectory(path, listCallback);
|
|
|
}
|
|
|
|
|
|
+#if FEATURE_ASYNC_ENUMERABLE
|
|
|
/// <summary>
|
|
|
- /// Asynchronously retrieves list of files in remote directory.
|
|
|
+ /// Asynchronously enumerates the files in remote directory.
|
|
|
/// </summary>
|
|
|
/// <param name="path">The path.</param>
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
|
|
|
/// <returns>
|
|
|
- /// A <see cref="Task{IEnumerable}"/> that represents the asynchronous list operation.
|
|
|
- /// The task result contains an enumerable collection of <see cref="SftpFile"/> for the files in the directory specified by <paramref name="path" />.
|
|
|
+ /// An <see cref="IAsyncEnumerable{T}"/> of <see cref="ISftpFile"/> that represents the asynchronous enumeration operation.
|
|
|
+ /// The enumeration contains an async stream of <see cref="ISftpFile"/> for the files in the directory specified by <paramref name="path" />.
|
|
|
/// </returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
|
|
|
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
- public async Task<IEnumerable<ISftpFile>> ListDirectoryAsync(string path, CancellationToken cancellationToken)
|
|
|
+ public async IAsyncEnumerable<ISftpFile> ListDirectoryAsync(string path, [EnumeratorCancellation] CancellationToken cancellationToken)
|
|
|
{
|
|
|
CheckDisposed();
|
|
|
|
|
|
@@ -616,7 +620,6 @@ namespace Renci.SshNet
|
|
|
|
|
|
var fullPath = await _sftpSession.GetCanonicalPathAsync(path, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
- var result = new List<SftpFile>();
|
|
|
var handle = await _sftpSession.RequestOpenDirAsync(fullPath, cancellationToken).ConfigureAwait(false);
|
|
|
try
|
|
|
{
|
|
|
@@ -634,18 +637,16 @@ namespace Renci.SshNet
|
|
|
|
|
|
foreach (var file in files)
|
|
|
{
|
|
|
- result.Add(new SftpFile(_sftpSession, basePath + file.Key, file.Value));
|
|
|
+ yield return new SftpFile(_sftpSession, basePath + file.Key, file.Value);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
await _sftpSession.RequestCloseAsync(handle, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
+#endif //FEATURE_ASYNC_ENUMERABLE
|
|
|
|
|
|
/// <summary>
|
|
|
/// Begins an asynchronous operation of retrieving list of files in remote directory.
|