FTP client application encounters slow file download performance issue.



The FTP client is a .net client application. It invokes wininet.dll to download files from FTP.

The application downloads ftp files much slower than FTP.exe and other 3rd party ftp client application.

Its speed is  <500kb with a 1000M network link.


I collect Network Monitor log to begin the troubleshooting. When the FTP client downloads file, many TCP acknowledge packages are delayed for 10~200ms. The delays of acknowledges accumulate and  caused the slow download speed.

And the window size of acknowledge packages is getting smaller and smaller.

This symptom shows that the FTP client application cannot process the data efficiently and requests the FTP server to slow down data transmission.

After checking the code, I find it invokes FtpGetFile like below which is incorrect:

        FtpGetFile(hInternetConnection, filename, filename, false, INTERNET_FLAG_RELOAD, 0, 0);

According to the document, INTERNET_FLAG_RELOAD == 0x80000000 and it should be assigned to the last 2nd parameter. 0x80000000 at the last 3rd parameter means FILE_FLAG_WRITE_THROUGH. This flag can impact disk write performance significantly. See this document http://support.microsoft.com/kb/99794


The code is corrected to below one and it is working fantastically now.

        FtpGetFile(hInternetConnection, filename, filename, false, 0, INTERNET_FLAG_RELOAD, 0);




Juntao Zhu


Comments (2)

  1. Garry Trinder says:

    The FTP protocol can be accessed through the FtpWebRequest and FtpWebResponse classes in the System.Net namespace, and was introduced in .NET 2.0.

    This is another way to do FTP in .NET applications, which includes 100% managed code (WinInet is a Win32 library).

Skip to main content