Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1248
  • Last Modified:

FTP using wininet.dll lacks timeouts

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.
  • 5
  • 5
1 Solution
Anthony PerkinsCommented:
I too created an FTP download OCX modelled after Mabry's FTP control (same Properties, Methods and Events).

I therefore find it odd that you would get a timeout when executing FtpFindFirstFile or InternetReadFile.  In my experience this usually happens only when you connect. In any case an error is raised fairly immediately. On the other hand I only connected, downloaded/uploaded and disconnected.

But to answer your question, my understanding is that it is near impossible to write an asynchronous FTP control with the WinInet controls using VB.  There are articles on MSDN that confirm this.

So in conclusion, if this is an exercise and you have plenty of free time than go ahead, however I would strongly recommend you use a commercial control such as Mabry's.
MrBunnyAuthor Commented:
Eddy, I checked out that question earlier, and the did fix SOME of the hangups, but i am getting the hangup on a file that i just downloaded 30 seconds earlier, so it's not a machine unavailability issue.

ACPerkins,  I downloaded the Mabry's controls.  Not having to reinvent the wheel sounds like a great idea.  Lemme go make sure it works before I award you the points :P  

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Anthony PerkinsCommented:
I am not after the points, so much as to avoid any unnecessary pain on your part. If it would be of any help I can send you the code I have for the FTP OCX.

MrBunnyAuthor Commented:

Sample code would be neat!  I've mostly created the application, but there seem to be a few bugs left and perhaps you code could give me some insight.

I am a little new to the Packaging and Deployment wizard, and I must be messing it up somehow because Mabry's controls don't seem to work on the installation destination machine.  I get an error:
Mabry FTP/X Control
Could not create FTP/X COM Object.  Please ensure that FTPX.dll is installed and registered.

I added the FTPX.dll (and the ADO whatever they suggest in thier FAQ) to my installer, and now when i install it on winME machine, it just keeps saying it needs to upgrade everytime i install.  

MrBunnyAuthor Commented:
Update:  I installed it on a Win98 machine.... apparently it didn't like the win2k .dll's i had included in it, and I totally hosed the machine.  I fixed it (eventually) by overwriting the .dlls with originals from a clean win98 install.  

I am a little wary now.... can you explain exactly how you are supposed to package the MAbry control?
Anthony PerkinsCommented:
Give me a couple of days to package the class up and give you a sample.  For the most part it is pretty straight forward, but the sample would help.

I have never had any problems with installing Mabry controls.  I assume you are using the registered version. If you have any questions, check out their knowledge base. If that does not give you any answers, try emailing them, they have been extremely helpfull in the past, but it has been some years since I needed to contact them.

MrBunnyAuthor Commented:
Just a quick question, what are you supposed to package?
I got:
ccrpTimr6.dll (a support .dll)
QuickDownloader.exe (mine)
VB6 runtime and ole automation

When it crashed I had also packaged:
(because I thought that's what the mabry control required, but my win2k versions seem to have been a bad idea to include).

Does this sound right?  It seems to be working, but...
Anthony PerkinsCommented:
I was just referring to the code (three classes) and the sample.  I can send you the three classes right now if you want and you can let me know if you need samples to see how it works.

MrBunnyAuthor Commented:

I would love to see your sample code in whatever format is most convenient.  Don't trouble yourself too much with making it run perfectly, i just want to see what patterns you used to do thing.

As a separate question, I am trying to make sure I am packing the Mabry Control properly.  I had never packaged a 3rd party control like Mabry's before, so I am not sure I am doing it right.  I mentioned earlier my list of files that I was including in the packaging, but I wonder if I am missing some, because the Mabry documentation mentions that the control require some support dlls (like OLE32.dll) that I am not including.  This hasn't been a problem so far, perhaps those support .dlls are only needed for win95 machines or something.

If you happen to have ever packaged up an application containing a Mabry control (particularly the FTP one) I would love to see the packing to make sure I am doing it right.

So if you e-mail me your favorite samples I would be much obliged.

-Mr Bunny.  =:x)
Anthony PerkinsCommented:
I have sent you the code with the three classes.

Regarding Mabry's FTP control, you should be using the FTP/X control which uses the ATL model and unlike their old FTP control it does not require the MFC class DLL's.

Also, I suggest you take a look at the FTP section of their FAQ.  In particular the following question should help:
What are the differences between FTP and FTP/X?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now