# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  VB Downloader. Download files from the web, with prog bar.

## Wokawidget

There are 2 downloader projects attached here. 1 asynchronous project and 1 synchronous project.

The synchronous downloader, vbDownloader.zip, uses the URLDownload API and uses call backs to allow the user to cancel the download and/or show a prog bar.

For this project to work you need to do the following:

Attached is code, plus a demo app, that allows you to download files from the web.
This can be used for auto updates for a client exe etc, or just as a download manager.

One thing you need to do is download the file:

http://www.mvps.org/emorcillo/download/vb6/tl_ole.zip

and extract the 2 tlb files and install them using the instructions provided.

These tlb files are used for the call back to allow the download to be shown in a progress bar, and to allow the user to cancel the download.



The 2nd project "Downloader and Winsock.zip" is an asynchronous downloader that uses a DLL version of the winsock control.
This has a few benefits over the URLDownload method. 1stly it's asynchronous and there you can have multiple downloads at any one time in your app, plus it allows you to use your app while downloading. It also allows you to get the file size of the file before you download it. This I find is very usefull.
However, the URLDownload example allows you to cache the file in the internet cache folder....this can be handy. The winsock does not cache any of the file, and if the download is aborted cancelled you will have to download the whole file from scratch.

Pick ya method  :Big Grin: 

Woka

----------


## kleinma

hey where's my name in the credits  :Frown:   :Frown:   :Frown:

----------


## TheVader

Nice code, worked fine for me in the IDE.  :Smilie:  But when I compiled both files (vbWebDownload.dll and DemoDownloadApp.exe) the app didn't work anymore. When trying to download a file the app hangs and after a while says 'Download aborted. Resource not found.' Without error handler it gave me a 'Object variable or With block variable not set' error and an Automation error. Does this happen with anyone else when the app is compiled?  :Smilie:

----------


## Wokawidget

When you copyied both the tlb files to system32, did you register them using the instructions on the web site, or did you just browse to the files in VB and register them that way?

Just asking as that's the only thing I can think of off the top of my head.

Will have a go myself tomorrow to see if I can crash it.

Woka

----------


## NoteMe

Sorry...but no more downloading for you...my domain went out today...I have a backup of your files though. And I can upload it as fast as I get the new server up and running if you want that....



ØØ

----------


## Wokawidget

Arrrrrgh! Who do you think you are taking down your own server!  :Frown: 

Hehehe

Yea, that would be good if you could. They were for my live update code anyways...so wrong thread   :Thumb:  

Woka

----------


## NoteMe

Oppps....well let me continue in the wrong thread then... :Smilie: 

I have my new host, more or less up and running, some countries might not reach it before a day or two. But at least it is up again. You might have to check if it is still working though. I don't know squat about DNS and stuff...but it is somehow chaned, but the name is still the same, just the IP that has changet I guess.


ØØ

----------


## dos5731

it works here.

----------


## willytb

Hope it's not too late to reply to this.....

I can't seem to get the vb downloader code to work I have added the reference to olelib.tlb but when I run the code i get:

Compile error user-defined type not defined?
WithEvents mobjDownload As Download

Also I got a lot of .inc files with the .tlb file but didn't see any instruction in the zip? Only found one file to reference olelib.tlb?

Bill bowman

----------


## Wokawidget

That can be a bit messy to setup from what I've heard  :Frown: 

Have you tried the 2nd download, the one that uses a custom winsock class.?
This is a much better download project in my opinion.

In your main app do you have reference to vbDownloader?

Woka

----------


## willytb

Thanks for your quick response.   I have gotten it working now and really like how well it works. Not completely sure how to integrate the code into my project though. Can I just copy the frmMain code into my project and reference the vbwebdownload.dll?

----------


## Wokawidget

Nice one.

Yup. Just copy frmMain into your app then ref the dll.
Although I would suggest looking at the winsock method, as it's aysnchronous, which has much wider benefits.

Woka

----------


## Mythrandil

Hey,

i know its abit late in the day for this thread but just incase sum1 cares.

I was having trouble getting the winsock version working, constantly getting an error 53, turns out it raises an error if the file you want to download doesnt already exist on your computer   :Confused:  

adding a copy where you want to download gets around this but seemed like a funny thing to raise an error about. It downloads and overwrites existing file anyway.(might want to add user warning/input to this) :P

----------


## Wokawidget

That is true, but i didn't want my code automatically overwriting files  :Smilie: 
You can add this code that deletes the old file in your UI code...

Woka

----------


## Mythrandil

> That is true, but i didn't want my code automatically overwriting files 
> You can add this code that deletes the old file in your UI code...
> 
> Woka


yes ofc.

however from my understanding it does the opposite

in the download class module:

If Dir(mstrLocalPath & GetFilename(mstrRemoteFile)) = vbNullString Then
Err.Raise 53

means an error is raised if what you want to dl doesnt exist on local drive, surely should be the opposite ???

If Dir(mstrLocalPath & GetFilename(mstrRemoteFile)) <> vbNullString Then
Err.Raise (overrite error)

----------


## Wokawidget

Bad woka *slap*

Yes, you are correct  :Smilie: 

Woof

----------


## Aeric

Thanks Woka. Just what I am looking for.

----------


## isnoend07

> Nice code, worked fine for me in the IDE.  But when I compiled both files (vbWebDownload.dll and DemoDownloadApp.exe) the app didn't work anymore. When trying to download a file the app hangs and after a while says 'Download aborted. Resource not found.' Without error handler it gave me a 'Object variable or With block variable not set' error and an Automation error. Does this happen with anyone else when the app is compiled?


Hope i can get an answer to this old thread. I am having the same problem works good in ide  but compiled exe gives me the same error you stated:
download aborted resource not found
Did you ever get a fix?

----------


## amolt

Hi WOKA,

I used your vbDownloader project using OLE and it works great for me!!
Thanks for that!!!!

But though there is a big problem that *How can I use it to download multiple files from my URL?* 
I'm using VB6 and downloading Images from my URL. And I need to download multiple files at the same time the process started for any file.

As I'm not able to understand how to use the OLE Interfaces I request for the resources to understand that properly and useful for Development.

Waiting for reply ...

Thanks ,,
AmolT.  :Confused:

----------


## Wokawidget

You need to use the Download Code + Winsock download from my 1st post and create multiple downlaod classes...or combine my multithreading code with the OLE downloading code.

Personally I would go for the 1st option as this is already async.

Woka

----------


## grrmisfit

i know this is an old thread but  i just came across it. using the non winsock version it works just as i need it to but the issue i have is what if we dont know the file name to be used? like getting files from a php page? the filename is unkown thus no idea what to save it as

----------


## Wokawidget

How can the filename be unknown???
Just save it as a tempt file name then? make one up.

woka

----------


## grrmisfit

cause you dont know what file your grabbing. its a php script and by entering in a random number it sends you a file but it could be a jpg gif you just dont know. so what im basicly looking to do is send the link then using  a for loop on a set number range to enter in the numbers i want. then it download the file. i tried making use of the internet controls but it works just like if i was  using a webbrowser and some files like jpg get opened within the browser instead. if the download box would just open for all files i could easily use api to manipulate the box

----------


## EmbajadorMX

Dear Woka, 

Just what I was looking for, GREAT !!!

As Mythrandil, when I run the code I got error 53, I'm looking to solve this as he posted.

But I have one question about the license of this code... Can I use it royalty free? what kind of license does it has?

Thank you !

----------


## kleinma

error 53 is usually a file not found error.

----------


## EmbajadorMX

Thank you kleinma!

I see you are a moderator in this group. Please tell me about the licence of the code found on this forum. Can I use that code freely?

----------


## Wokawidget

Hi,

That's correct. File not found. What line is this happening on?

You can use all my code posted on VBF for free.

If you want to add me into the "about" section of your app then that's a bonus  :Smilie:  but not essential  :Big Grin: 

Woka

----------


## kleinma

It is always good to give people credit where credit is due.

So as woka says, he offers his code up for free for anyone to use because he is a nice guy. So if you use his code and it saves you a lot of time, its always nice to give him a little credit in your about screen or readme file.

----------


## EmbajadorMX

Thank you Woka! 

Of course I'll credit you on my project. 

About the error that raises every time I try to download a file, let me explain:

Every time I click the "get file info" button, i got a success message, telling me the size of the file.

Every time I click the "download file" button the application raises error 53, telling me that the file doesn't exist... that is correct because is the first time I try to download it.

I see the error raises on the OpenFile() subroutine, but I don't know how to fix it. Would you please help me, dear Woka? If you try to replicate this behaivor you must delete the file in the download directory, because if it exists before the download begins and no error will be raised.

Thank you for your time!

----------


## Wokawidget

np  :Smilie: 
Which line is this happening on?
Which downloader project  is this?
What file is it trying to open?
Does the path exist?

Woka

----------


## EmbajadorMX

Hi Woka!
*
The project is:* "Downloader and Winsock" located at http://www.vbforums.com/showthread.p...hreadid=310235
*Which line is happening on*: is on the sub OpenFile() on Download.cls
*What file is trying to open*:  I really don&#180;t know, because no file have been downloaded yet
*Does the path Exist*: yes, it exists.

I hope you can help me solve this.

Thank you!!!

----------


## EmbajadorMX

Dear Woka It&#180;s WORKING!!

I understand what&#180;s going on. I&#180;ve solved, now it&#180;s working!

It downloads files asynchrously! you have done a great work.  Thank you!!!

----------


## EmbajadorMX

Hi Woka!

I have one more question related to the proyect Downloader and Winsock located at http://www.vbforums.com/showthread.p...hreadid=310235 

The download works ok, now I made the call from a new form inside the same project, but the connection can&#180;t be made. I created a new object "download" and applied it&#180;s methods, It starts the connection but It can&#180;t success. 

How the download object must be used from another form within the project?

Thank you for your time!

----------


## Wokawidget

:Smilie: 
Using the code on diff forms doesnt seem to be the problem.

Why does it not connect? Do you get an error?

Woka

----------


## EmbajadorMX

Upss...!

It&#180;s my failure... I tried to connect to a site which was up at certain time, but for some reason this site went down exactly when I tried the connection using the new form. Your program works correctly.

Thank you for all your support Woka!

----------

