Skip to content

Commit

Permalink
Fixed SftpClientConnection.ListDirectoryAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoUrsino committed Aug 6, 2024
1 parent 5720b42 commit 52a2cbe
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions Ark.Tools.FtpClient.SftpClient/SftpClientConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public override async Task<IEnumerable<FtpEntry>> ListDirectoryAsync(string path
path ??= "./";
await _ensureConnected(ctk);

var rawLs = await _client.ListDirectoryAsync(path);
return _parse(rawLs);
var rawLs = _client.ListDirectoryAsync(path, cancellationToken: ctk);
var res = new List<FtpEntry>();

await foreach (var file in rawLs)
{
res.Add(_parse(file));
}

return res;
}

private async Task _ensureConnected(CancellationToken ctk)
Expand Down Expand Up @@ -210,19 +216,24 @@ private List<FtpEntry> _parse(IEnumerable<SftpFile> files)

foreach (var file in files)
{
var entry = new FtpEntry
{
FullPath = file.FullName,
IsDirectory = file.IsDirectory,
Modified = file.LastWriteTimeUtc,
Name = file.Name,
Size = file.Length
};
FtpEntry entry = _parse(file);
result.Add(entry);
}
return result;
}

private static FtpEntry _parse(ISftpFile file)
{
return new FtpEntry
{
FullPath = file.FullName,
IsDirectory = file.IsDirectory,
Modified = file.LastWriteTimeUtc,
Name = file.Name,
Size = file.Length
};
}

public override async ValueTask ConnectAsync(CancellationToken ctk)
{
if (_client.IsConnected)
Expand Down

0 comments on commit 52a2cbe

Please sign in to comment.