Sign in to follow this  
ARC inc

Downloading files via http/ftp [C++]

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this