C# 快速从FTP服务器下载多个文件

C# 快速从FTP服务器下载多个文件,c#,.net,performance,ftp,C#,.net,Performance,Ftp,我想使用C从FTP服务器下载数千个较小的文件。使用我当前的代码,我无法达到超过100 KB/s的速度,通常要慢得多,我正在本地FileZilla FTP服务器上测试 这是我的代码: foreach (var file in files) { //Client is basically a WebClient var stream = Client.OpenRead(new Uri(_serverRootPath + file.Replace(@"\", "/")));

我想使用C从FTP服务器下载数千个较小的文件。使用我当前的代码,我无法达到超过100 KB/s的速度,通常要慢得多,我正在本地FileZilla FTP服务器上测试

这是我的代码:

foreach (var file in files)
{
    //Client is basically a WebClient
    var stream = Client.OpenRead(new Uri(_serverRootPath + file.Replace(@"\", "/")));

    var filePath = _clientRootPath + file;
    if (!Directory.Exists(Path.GetDirectoryName(filePath)))
        Directory.CreateDirectory(Path.GetDirectoryName(filePath));
    var fileStream = new FileStream(_clientRootPath + file, FileMode.Create);

    const int bufferSize = 8192;
    var buffer = new byte[bufferSize];
    var readCount = stream.Read(new byte[bufferSize], 0, bufferSize);

    while (readCount > 0)
    {
    await fileStream.WriteAsync(buffer, 0, readCount);
    readCount = await stream.ReadAsync(buffer, 0, bufferSize);
    }

    stream.Close();
}

任何帮助都将不胜感激。

您是否尝试过并行运行此功能?如果你的连接速度是这里的瓶颈,那么它不会有帮助,否则值得一试。
查看示例。

与仅下载1个大文件相比,网络速度如何?@Vlad 13MB的文件在不到一秒钟的时间内传输完毕。