download in parallel
This commit is contained in:
12
Program.cs
12
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)
|
static async Task RecurseDirectory(SftpClient client, string source, string destination, bool deleteDirectory, CancellationToken token)
|
||||||
{
|
{
|
||||||
Log.Information($"Scanning directory '{source}'");
|
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)
|
if (item.IsDirectory)
|
||||||
{
|
{
|
||||||
var newPath = Path.Combine(destination, item.Name);
|
var newPath = Path.Combine(destination, item.Name);
|
||||||
await RecurseDirectory(client, item.FullName, newPath, true, token);
|
await RecurseDirectory(client, item.FullName, newPath, true, token);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await DownloadFile(client, item, destination, token);
|
await DownloadFile(client, item, destination, token);
|
||||||
Log.Information($"Deleting '{item.Name}'");
|
Log.Information($"Deleting '{item.Name}'");
|
||||||
await client.DeleteAsync(item.FullName, token);
|
await client.DeleteAsync(item.FullName, token);
|
||||||
}
|
});
|
||||||
|
|
||||||
if (deleteDirectory)
|
if (deleteDirectory)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user