How to download a file from the web?

Please discuss general Delphi programming topics here.

How to download a file from the web?

Postby Tronix » January 18th, 2005, 12:15 pm

Hey! I couldn't find this subject in any thread so here goes:

I want to write an application (in Delphi) that can download certain files from a web-site.

Fx. If the user press a button the program downloads www.some-url.com/somefile.dat and saves it on the HD.

How do I do that?

/Valdemar
Tronix
Member
Member
 
Posts: 3
Joined: January 18th, 2005, 12:11 pm
Location: DK - Denmark

Postby Stefan » January 18th, 2005, 8:21 pm

Hi,

You could use Indy (look for that on google) or use the Microsoft provided DLL's, for that take a look on:

http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/moniker/reference/functions/urldownloadtofile.asp

which is, I believe, declared in urlmon.pas...

Cheers,
Stefan

ps. If you need specific code, I'll be able to provide some of it as I've worked with this before, but I won't be able to acces the code untill tomorrow...
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Postby Tronix » January 19th, 2005, 11:03 am

a little source would be nice..

I tried the urlmon module, but I get the BindStatusCallback.OnProgress()-function to work correctly :(

\Valdemar
Tronix
Member
Member
 
Posts: 3
Joined: January 18th, 2005, 12:11 pm
Location: DK - Denmark

Postby Stefan » January 19th, 2005, 11:22 am

alrighty...

http://groups.google.nl/groups?q=Delphi+URLDownloadToFile+bsc&hl=nl&lr=&selm=cscem4%24hm7%241%40inews.gazeta.pl&rnum=1

I'm not on my laptop right now so I can't acces my code, but that's some useful code showing how to work with the IBindStatusCallBack interface...

Cheers,
S
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Postby Tronix » January 19th, 2005, 11:30 am

That works perfect...

Thank you very much!

\Valdemar
Tronix
Member
Member
 
Posts: 3
Joined: January 18th, 2005, 12:11 pm
Location: DK - Denmark

Postby Stefan » January 19th, 2005, 11:42 am

Please keep in mind that there might be more to it than this.
When downloading via Internet Explorer you get all the "nice features" included, like caching for instance:

Suppose you download "program.exe" twice; first time it's version 1.0 and the second time it's version 2.0; second time IE might just "download" the cached version 1.0 and not the intended version 2.0...

Apart from that I've found downloading via proxies doesn't always work and if the user doesn't use IE and therefor his/hers settings in IE are screwed up, you will not be able to download either...

Cheers,
Stefan
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron