public async Task DownloadFileAsync(string fileName, IProgress<int> progress)
{
using (var fileStream = ...) // Open local file for writing
using (var ftpStream = ...) // Open FTP stream
{
while (true)
{
var bytesRead = await ftpStream.ReadAsync(...);
if (bytesRead == 0)
return;
await fileStream.WriteAsync(...);
if (progress != null)
progress.Report(bytesRead);
}
}
}