2014-07-16 124 views
0

我想使用C#從FTP服務器下載許多(千)更小的文件。使用我當前的代碼,我無法達到超過100 KB /秒的速度(通常慢得多)(我正在本地FileZilla FTP服務器上測試)。從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(); 
} 

任何幫助,將不勝感激。

+0

網絡速度與僅下載1個大文件時相比如何? – Vlad

+0

@Vlad一個13MB的文件在不到一秒鐘內就被轉移了。 – davidwroxy

回答

相關問題