Home
> Windows API > Download files from Internet through code
Download files from Internet through code
Use URLDownloadToFile.
An article on this API is here, with a demo application.
Use URLDownloadToFile.
An article on this API is here, with a demo application.
Yami, BITS is a COM object, so there’s no reason why you shouldn’t be able to use it, so long as your copy of VC 6 is up to date- check MSDN to be sure. Please feel free, to drop me a line if you want some sample code and I’ll send it to you. Be warned though, that BITS is designed to use spare bandwidth, so any solution you come up with may not be as fast as URLDownloadToFile. Good luck, Karl
🙂
Karl has given his e m a i l address, maybe you can try asking him.
I got the same problem of “hanging” upon losing connection (unplug) while using URLDownloadToFile(). The program only prompt my callback AFTER I plug back and have internet connection. I’m using VC6 and I’m not sure if BITS is available. Any help will be appreciated.
Finally managed to get my BITS replacement for URLDownlodToFile working.
It’s not the prettiest piece of code I’ve ever written, since I’ve had to Mac Guyver it to do what I wanted. Oh well, all part of the joy of programming I suppose. If anyone has any problems with URLDownloadToFile, drop me a line at tomlinsonkarl A-T-H-O-T-M-A-I-L-D-O-T-C-O-M AND I’ll send you a copy of what I wrote. It’s not pretty, but it may help.
I like function UrlDownloadToFile, hope MS will fix such issues! If BITS works then it’s worth the effort! 🙂
All the best!
Hi Nibu,
the code that I was looking at was (I think) something by Chris Maunder, whose excellent website has saved my bacon on innumerable occasions. But not this time, sadly. I’m really beginning to get annoyed with Vista.
Over on the MSDN forums, it seemed that someone else was having a similar problem with URLDownloadToFile, and it was suggested that they try using BITS (Background Intelligent Transfer Service). This is a great pity since I’ve now replaced an elegant one line function call (albeit with a separate callback) with a hundred or so lines of mostly boilerplate COM! Oh well, that’s progress, I suppose.
Yeah looks bit clunky, but if it works should be fine since we don’t have another option. 🙂
By the way is that Chris or Michael Dunn. 😉
Hi Nibu,
thanks for the reply. I noticed Chris’s article a while back, but a quick glance at his code gave me an idea:
if ( m_bUseTimeout && CTime::GetCurrentTime() > m_timeToStop )
return E_ABORT;
It’s a bit clunky but I’ll give it a whirl. Thanks for pointing me in that direction.
Karl
Karl,
There is an article in CodeProject with a demo application, here is the link
http://www.codeproject.com/KB/IP/urldownload.aspx.
I don’t have vista hence can’t say, Hope this link gives you some help!
Hi Nibu,
UrlDownloadToFile is a great function- efficient and easy to implement a callback to. But… let’s say you call UrlDownloadToFile and lose your network connection. Under XP, the function exits, and one can start to pick up the pieces. Under vista, the function just hangs- there’s no indication of an error condition, not even through the callback. Any ideas?