• Advertisement
Sign in to follow this  

Downloading files via http/ftp [C++]

This topic is 3085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright I've looked all over an can't find anything that is understandable could someone help me with this? I am trying to make a program that can download from a website or ftp even both. Any suggestions on how to do this? Not Looking for anyone to code it for me but maybe some hints or some links that might direct me to this type of thing. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I found some articles on example-code.com with a quick search. Looks like you have to use their libraries, but it's a start. Links: FTP and HTTP.

Share this post


Link to post
Share on other sites
You need to create a TCP socket, and connect to the web-server (usually on port 80). Then you send an HTTP-header, and the server will send the response to you.
The HTTP specification is available here: http://www.w3.org/Protocols/rfc2616/rfc2616.html.

The basic header you send is as below. \r\n is a carriage return, byte 0xD followed by 0xA, and means end of line. Two carriage returns means end of the header, and after you send that you will get a response from the server. The response will start with an HTTP response-header, followed by the file-data.

Request:

GET /filepath/file.html HTTP/1.1\r\n
Host: www.the-server-address.com\r\n
\r\n
\r\n


Response:

HTTP/1.1 200 OK\r\n
Date: ...\r\n
Content-Type: text/html or something\r\n
Other headers: ...\r\n
\r\n
\r\n
<file data>


Try it out by connecting with telnet or something to a web-server and request a small file, which should be returned as text.

Share this post


Link to post
Share on other sites
For Windows? Maybe try here.

Specifically, note the InternetReadFile function. I've never used that library (WinINet), but it appears to be perfectly acceptable.

Share this post


Link to post
Share on other sites
I would like to second libcurl, especially if you are just looking for something that will "just do it". The hardest part of using libcurl was getting a version of it to compile as a static lib that would work with my app, though there are plenty of pre-compiled versions linked to by their website.

Once I got it compiling, it was literally a 20 minute process to learn everything I needed to hit a webpage and download the contents.

Share this post


Link to post
Share on other sites
I want to "third" libcurl.

It's a great tool.

I shipped a game using it, and in fact if you look at spore, I believe it has the libcurl libraries shipped in there too (:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement