download in parallel
This commit is contained in:
@@ -107,21 +107,21 @@ static async Task RunJob(Config config, CancellationToken token)
|
||||
static async Task RecurseDirectory(SftpClient client, string source, string destination, bool deleteDirectory, CancellationToken token)
|
||||
{
|
||||
Log.Information($"Scanning directory '{source}'");
|
||||
await foreach (var item in client.ListDirectoryAsync(source, token))
|
||||
await Parallel.ForEachAsync(client.ListDirectoryAsync(source, token), token, async (item,token) =>
|
||||
{
|
||||
if (item.Name is ".." or ".") continue;
|
||||
if (item.Name is ".." or ".") return;
|
||||
|
||||
if (item.IsDirectory)
|
||||
{
|
||||
var newPath = Path.Combine(destination, item.Name);
|
||||
await RecurseDirectory(client, item.FullName, newPath, true, token);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
await DownloadFile(client, item, destination, token);
|
||||
Log.Information($"Deleting '{item.Name}'");
|
||||
await client.DeleteAsync(item.FullName, token);
|
||||
}
|
||||
});
|
||||
|
||||
if (deleteDirectory)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user