Exemple #1
0
        private async Task DownloadFileAsync(FluentFTP.FtpClient client, string remotePath, StorageFile localFile, CancellationToken token, IProgress <double> progress)
        {
            await semaphore.WaitAsync();

            try
            {
                string remoteDirectory = Path.GetDirectoryName(remotePath);
                string remoteFileName  = Path.GetFileName(remotePath);
                await client.SetWorkingDirectoryAsync(remoteDirectory);

                using (var stream = await localFile.OpenStreamForWriteAsync())
                {
                    await client.DownloadAsync(stream, remoteFileName, token, progress);
                }
            }
            finally
            {
                client.Dispose();
                semaphore.Release();
            }
        }