To reproduce the issue:
1. Put a zero byte file on a FTP site.
2. Call InternetOpen() with flag INTERNET_FLAG_ASYNC
3. FtpOpenFile() to download the file.
Wininet will send out a FTP request. After receiving the response, the registered callback procedure will receive an INTERNET_STATUS_REQUEST_COMPLETE event.
4. Call FtpOpenFile() again.
This time Wininet will not send out any FTP request, nor raise the INTERNET_STATUS_REQUEST_COMPLETE event.
The application will then hang if it waits for the above event.
This issue happens only if in asynchronous mode. A zero byte file can always reproduce the issue.
Troubleshooting:
There is a Wininet asynchronous mode sample about how to download HTTP files: http://msdn.microsoft.com/en-us/library/cc185684(VS.85).aspx
Although it is HTTP not FTP, we can learn some ideas from that sample.
Solution:
After test and test, it was found that if we add flag INTERNET_FLAG_RELOAD when calling FtpOpenFile(), it began to work properly.
FtpOpenFile(hFtp_,path,GENERIC_READ,FTP_TRANSFER_TYPE_BINARY|INTERNET_FLAG_RELOAD,reinterpret_cast<DWORD_PTR>(this));
According to http://msdn.microsoft.com/en-us/library/aa383661(VS.85).aspx :
Read more: AsiaTech: Learning by Practice