Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > download files


Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2002, 09:16 AM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Question download files


I like to download .ZIP files from a http address (no ftp!) and store them to the harddisk.

I'm not sure if I have to use inet or winsock to do this.

With inet I was able to download from ftp only not http :-(

Thanks for help

Stefan
Reply With Quote
  #2  
Old 03-03-2002, 09:55 AM
Bucky's Avatar
Bucky Bucky is offline
A+ Certified Nerd

Retired Leader
* Expert *
 
Join Date: Dec 2001
Location: East Coast
Posts: 1,763
Default Inet will work apparently

__________________
If you're not part of the solution, you're part of the precipitate.
Reply With Quote
  #3  
Old 03-03-2002, 12:11 PM
haoli12345
Guest
 
Posts: n/a
Default

This is what I would do I would put a webbrowser control and let it to navigate to http://www.server.com/file.zip.


-Hao Li-
Reply With Quote
  #4  
Old 03-03-2002, 04:50 PM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Question

Thanks,

in the meantime I found a way to download with the inet also with http. :-))

One more question:
How can I get the filesize before I start the download as I like to show the percent of the downloaded file with a processbar.

Thanks for help again.
Reply With Quote
  #5  
Old 03-04-2002, 05:06 AM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Default

I use

Code:
bData() = Inet.OpenURL(strURL, icByteArray)
in order to download a file now, but how can I get the filesize for this file???

Thanks for help.
Reply With Quote
  #6  
Old 03-04-2002, 05:46 AM
divil's Avatar
divil divil is offline
Funky Monkey

* Expert *
 
Join Date: Nov 2001
Location: England
Posts: 1,289
Default

Why do you call yourself Wendy when your name is Stefan?
__________________
MVP, C#
Now you see why evil will always triumph - because good is dumb.
Windows Forms and WPF user interface controls
Reply With Quote
  #7  
Old 03-04-2002, 05:50 AM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Smile

it is a nickname as my lastname is wendt :-)

As Stefan was already used when I create this user I used wendy as user.

Stefan (or wendy)
Reply With Quote
  #8  
Old 03-04-2002, 12:26 PM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Default

Hello again,

it seems that my problem regarding the filesize is not as easy as I get no reply :-(

Maybe someone can help for this:
How can I see if a download has ended without errors, or if the filename was correct?

with

Code:
Private Sub Inet_StateChanged(ByVal State As Integer)
I can see many connection states but no state if download has finished with or without error :-(

Thanks again for a hint if I have to use winsock for these features.

Stefan
Reply With Quote
  #9  
Old 03-04-2002, 01:03 PM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

You need to use the icHTTP protocol to send a "GET" request to the server. The server will then respond with all sorts of information about the file you are trying to GET, including its size!

From there, within the Inet1_StateChanged() event of the Inet control, use the GetChunk() method to retrieve a fixed size chunk of the file.

You can then update the progress bar using a simple formula between how large the file is, and how much you've got already.

Edit: Here is a good link explaining the usage of the Inet control for file downloading. Enjoy.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #10  
Old 03-04-2002, 01:31 PM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Default

ChiefRedBull,

maybe you have a example code for this.
I tried this many times but it did not work :-(

HELP
Reply With Quote
  #11  
Old 03-04-2002, 01:38 PM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

I dont have any no, but I'll knock one together for you. Give me a day or two so its bug free enough to go in the Code Library when its done.

Until then - read and understand that link i gave you.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #12  
Old 03-04-2002, 01:56 PM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Default

thats great :-))

I already read it, but with HTTP it is not working :-(

I will try to find more informations about this topic in order to understand what a made wrong.

Stefan
Reply With Quote
  #13  
Old 03-04-2002, 03:21 PM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

HTTP is working.... and is proven by my nice little demo.

With a little searching on the net, I found this helpful site, and plenty of others.

My example is posted in the Code Library.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #14  
Old 03-05-2002, 12:24 PM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Smile

Thank you :-)

I already tested your code and the link you gave me, very interesting.
In the most cases I'm able to download the files but with some Links I can't receive the Header information, thus I receive a error 'icRequestFailed' in State 8.

This problem happend when the URL is as

'http://testserver.com/download.cfm?filename=mytestfile.zip'

When I use the IE with this URL it works! Any idea ??

I have no problems we I try to download files with following "style":

'http://www.testserver.com/download/test.zip'

One more question:
As I like to download more then one file (in sequence or at the same time) I tried to modify the code with a little loop but it doent work :-(

How can I download more than one file - it doesn't matter if async or sync.

Thanks for your professional help again.

Stefan
Reply With Quote
  #15  
Old 03-05-2002, 03:20 PM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

To download more than one file at a time is going to require specific code for your program. A loop will probably be needed somewhere, but I couldn't help more without actually seeing your code.

As for downloading from 'funny' URLs.... it should work fine. I just successfully downloaded this url
Code:
http://www.xtremevbtalk.com/attachment.php?postid=93137
Could you give me an actual example on the ones that aren't working?
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #16  
Old 03-06-2002, 04:34 AM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Default

I used the code from the library you provided and add a loop as follow:

Code:
Private Sub cmdGetFile_Click()
    
Do
i = i + 1
lURL = URL(i)
    Inet.Protocol = icHTTP
    Inet.Execute lURL, "GET"
Loop Until i = maxURL

End Sub
Where array URL(i) inculdes different URLs.

When I use this code only URL(i=maxURL) is downloaded, what means if maxURL=4, only URL(4) is downloaded but not URL(1..3).

Any idea why?

Regarding my other problem I suppose the problem was located to the fileserver as I had no problems to download single files
today :-)

Stefan
Reply With Quote
  #17  
Old 03-06-2002, 04:43 AM
Bucky's Avatar
Bucky Bucky is offline
A+ Certified Nerd

Retired Leader
* Expert *
 
Join Date: Dec 2001
Location: East Coast
Posts: 1,763
Default

I'm not not sure if this will help, but you might want to try a For...Next loop instead. Like this:

Code:
For i = 1 To maxURL
  lURL = URL(i)
  Inet.Protocol = icHTTP
  Inet.Execute lURL, "GET"
Next i
__________________
If you're not part of the solution, you're part of the precipitate.
Reply With Quote
  #18  
Old 03-06-2002, 05:13 AM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Once you've executed the "GET" request, you need to wait until that file has been downloaded before you execute another "GET" request, other wise your program will get confused, and not finish off any of the downloads completely.
TO this end, I suggest you have a form level boolean variable, called bflDownloadDone.
Set it to false before you execute, then when the download is completed set it to true.
Code:
For i = 1 To maxURL
  lURL = URL(i)
  Inet.Protocol = icHTTP
  bflDownloadDone = False
  Inet.Execute lURL, "GET"
  ' do nothing until the file has been 
  ' successfully downloaded
  Do While bflDownloadDone = False
    DoEvents
  Loop
Next i
In the Inet_StateChanged event, once you've saved the incoming file to disk, set the bflDownloadDone to True.

You might also want to have an error flag in there as well, so that if the download errors, your Do While bflDownloadDone = False loop doesn't continue for ever...
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #19  
Old 03-06-2002, 08:02 AM
wendy wendy is offline
Junior Contributor
 
Join Date: Jan 2002
Location: germany, frankfurt
Posts: 267
Default

It works, but only when I run the program in VB6.
When i create a .exe the program freez when I like to start the download :-(

could this be a problem of ' DoEvents' ?

I'm not sure what this command realy do.

Thanks for your help again!!

Stefan
Reply With Quote
  #20  
Old 03-06-2002, 12:08 PM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

DoEvents passes control back to the Windows OS, and allows it to catch up with any tasks that need doing. It basically means that your program doesn't take up all the resources of the system, and it also gives a little pause, to allow things like Winsock.SendData to complete successfully.

If you did a loop like this:
Code:
Do While bFlag = False
Loop
your program is likely to crash, or show up as [not responding] in the Task Manager.

Could you post the source thats causing the problem? If its quite long, attach a ZIP containing all the project files.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->