From 38322aa1c23596c4725c6ebe8d5d503f03567474 Mon Sep 17 00:00:00 2001 From: Boxfriend Date: Tue, 16 Dec 2025 23:26:58 -0500 Subject: [PATCH] download in parallel --- Program.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index 779ac56..c7769fc 100644 --- a/Program.cs +++ b/Program.cs @@ -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)) + 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) {