Page 1 of 1

How to download a file from the web?

PostPosted: January 18th, 2005, 12:15 pm
by Tronix
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

PostPosted: January 18th, 2005, 8:21 pm
by Stefan
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...

PostPosted: January 19th, 2005, 11:03 am
by Tronix
a little source would be nice..

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

\Valdemar

PostPosted: January 19th, 2005, 11:22 am
by Stefan
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

PostPosted: January 19th, 2005, 11:30 am
by Tronix
That works perfect...

Thank you very much!

\Valdemar

PostPosted: January 19th, 2005, 11:42 am
by Stefan
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