[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


FTP using wininet.dll lacks timeouts

Posted on 2001-07-14
Medium Priority
Last Modified: 2007-11-27
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.
Question by:MrBunny
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
LVL 26

Expert Comment

ID: 6283436
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6283711
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.

Author Comment

ID: 6283873
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  

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 75

Expert Comment

by:Anthony Perkins
ID: 6286658
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.


Author Comment

ID: 6288486

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.
e-mail: zi3oqz001@sneakemail.com

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.  


Author Comment

ID: 6288492
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?
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6290048
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.


Author Comment

ID: 6290831
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...
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6291107
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.


Author Comment

ID: 6292694

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)
LVL 75

Accepted Solution

Anthony Perkins earned 1000 total points
ID: 6299183
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?

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question