The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: AeroASM on May 26, 2005, 03:05:29 PM

Title: Download from web
Post by: AeroASM on May 26, 2005, 03:05:29 PM
I would like to make a program that when run downloads a particular file from the internet to my hard drive. Is there an easy way to do this, or do I have to use sockets and do everything manually?
Title: Re: Download from web
Post by: doomsday on May 26, 2005, 03:28:04 PM
I haven't played with programming and the net, but I'd suggest having a look at the FTPxxx APIs in your Windows docs.  Might be of some use.

regards,
-Brent
Title: Re: Download from web
Post by: Tedd on May 26, 2005, 04:21:46 PM
You can either do it the long way with sockets and handling all the http or ftp yourself..
Or you can use the Winsock 2 functions to handle most of the http/ftp stuff for you, but you still need to play with sockets and such :wink
(The functions are in "wininet.inc" - named, cleverly, Http.... and Ftp....)
Title: Re: Download from web
Post by: AeroASM on May 26, 2005, 04:24:36 PM
Thanks Tedd, I will research this.

If the file I want to download is of the form http://www.thing.com/thing.gif do I use Http... or Ftp...? I thought maybe Ftp because isn't Http designed specifically for HTML documents?

Also will this work under proxy?
Title: Re: Download from web
Post by: pbrennick on May 26, 2005, 04:34:21 PM
In the DL section on Iczelion's website is an example that does this.  He also has an example that opens a zip file and gets a particular file to download.  These are not in the Tutorial section but are in the DL section.

Paul
Title: Re: Download from web
Post by: Tedd on May 26, 2005, 04:37:14 PM
See in the url where is says "http://" - guess which one you should use  :wink
Http is used for files, whether they are webpages or pictures or binary files doesn't matter.
Equally, if the url is "ftp://" then you need to use ftp, but for most cases http is fine.

As for proxies... you should be okay, if there's anything to deal with, then those functions should take care of it.


* Iczelion's download program is a quick and dirty version, which does the http itself; it doesn't handle anything special, so it works when nothing goes wrong, otherwise it fails.
Title: Re: Download from web
Post by: Faiseur on May 26, 2005, 05:50:51 PM
"If the file I want to download is of the form http://www.thing.com/thing.gif do I use Http... or Ftp...? I thought maybe Ftp because isn't Http designed specifically for HTML documents?"

Hi AeroASM,

example "HTTP Downloader v1.5" of Iczelion is a little old... Simplest is with API "UrlDownloadToFile" (in your example "http").  Otherwise it is a little longer (but easy) with API Wininet (InternetOpen, InternetOpenUrl, InternetReadFile)... 

I do not know if I can show examples (?), it is also used in hack (webdownloader).

Title: Re: Download from web
Post by: Robert Collins on May 26, 2005, 06:05:47 PM
Quote from: AeroASM on May 26, 2005, 04:24:36 PM
If the file I want to download is of the form http://www.thing.com/thing.gif.....

Just put that link in the address window of your browser and it will download the thing.gif file for you or you can right click on the image that you see on the HTML document in either case it will be saved to your specified directory.
Title: Re: Download from web
Post by: AeroASM on May 26, 2005, 06:34:41 PM
Faiseur: Thanks, UrlDownloadToFile looks perfect.
Robert: I want it to be done automatically by my program.
Title: Re: Download from web
Post by: Robert Collins on May 26, 2005, 06:36:52 PM
Quote from: AeroASM on May 26, 2005, 06:34:41 PM
Faiseur: Thanks, UrlDownloadToFile looks perfect.
Robert: I want it to be done automatically by my program.

Oh, then that UrlDownloadToFile is the way to go
Title: Re: Download from web
Post by: hutch-- on May 27, 2005, 12:23:16 AM
If you want to do this as simple as possible, if I remember correctly you can do this with ShellExecute() by specifying a URL.
Title: Re: Download from web
Post by: thomasantony on May 27, 2005, 05:21:11 AM
Hi hutch,
   When you use ShellExecute it won't be exactly automatic. You will have to deal with the dialog box and all give the directory to save to etc. Best way, connect to port 80 send the command GET thing.gif . I think thats the way it works

Thomas :U
Title: Re: Download from web
Post by: Faiseur on May 27, 2005, 11:33:55 AM
I think that you did not test UrlDownloadToFile

:-)

Title: Re: Download from web
Post by: Robert Collins on May 27, 2005, 01:03:54 PM
Quote from: thomasantony on May 27, 2005, 05:21:11 AM
.....Best way, connect to port 80 send the command GET thing.gif . I think thats the way it works

That's the way I do it. There's one little problem however. If the server is a secured server (https) then you will have the secured handshaking stuff to wotk out and that's not easy and you don't connect on port 80 if it is https.
Title: Re: Download from web
Post by: Danesh on May 27, 2005, 02:06:30 PM
AeroASM,

If you have access to the server which you want to download from, or if you want to implement an automatic updater or something like that, you can write a server program which listens on a specified port and then communicate to the server from the program which wants to download something. Writing server program and communicate with it is so easy. In this way, you can also pass username, password, do any kind of encryption during sending, manage multiple connections, get any other information from the host before sending any file to it (this is useful for example for an update server to see which version should be sent to the host by evaluating its current version) and so on. If you decided to do so, just tell me. I have many source codes which you can use just by little changes. Also, in more complex cases you can use James' FastServer utility, downloadable from: http://www.jamesladdcode.com