I'm trying to put together a little file downloader app, and I'm having problems reliably downloading and enumerating files. I am connecting to various FTP servers using wininet.dll, and frequently, i am able to successfully download the file. Occasionally, the connection process stalls at either FtpFindFirstFile or InternetReadFile.
The connection will not generate an error message (I waited 10 minutes for one) and yet will not allow the program to continue. When I pull the cable, the command generate an error after 10 seconds or so about losing it's connection to the internet. These commands successfully generate an error when I'm not connected to the internet, it is only when they have a chance at a connection that they seem to get stuck. I can make connections again after disconnecting from the internet and retrying, or after restarting the app.
Is there a way to create a timeout such that the connection will fail and processing will continue? It looked like InternetSetOption (see MSDN for details) had a INTERNET_OPTION_CONNECT_TIMEOUT
timeout among many others, but I am having trouble figuring our how to declare the API to be able to test that theory. (I'm still learning the API stuff). If anyone could help me with the declarations and stuff, (and it works) i would gladly accept that as an answer.
Is there a way to force a timeout without using InternetSetOption? The interface is locked-up while I'm waiting, but perhaps there is a way to simulate a network disconnect after a timeout?
Alternatively, is there a way to execute the command in an asynchronous way? I found details on how to do this in MSDN for C++, but nothing for VB :(
Finally, am I shooting myself in the foot? Is FTP through wininet too buggy? I have seen a bunch of sample code, including the ones from MSDN, but can it be made into releasable quality code? Can I add enough error handling to make it work? I don't mind repeatedly attempting the connection, but i can't get around the locked-up program type error that I have now.
Oh, and to save some speedy replys:
No, i can't use OpenURL, so don't copy the sample code here
No, I can't use that ftpGet
both of those commands have been widely panned by people who tried to use them.
If source code would make this clearer, I'd be glad to paste it up here.