Sign in to follow this  

download a file from internet (TCP, linux)

Recommended Posts

Hi. For an assignment, I have to write some kind of communication system allowing transfer of files between remote machines. A part of it requires an agent to download a requested file from given internet address. This part is completely irrelevant to the assignment, and we're encouraged to use any means to acomplish it, including using external libraries or even other programs (assuming they can communicate with rest of the system). I haven't got any clue on how to download a file from the net, so I'm searching for: 1. some guidance on how to write it. 2. a library that I could incorporate into my program. 3. an external program, that could be called with request to download a file. I think 2. is preferable. What is important - it has to work on linux, winsock is a no-no (wheater I like it or not (which I don't)). Any clues? EDIT: oh, and I'm using C++, if that's not obvious (linux)

Share this post

Link to post
Share on other sites
I would use wget. Just call something like:

std::string cmd = "system '";
cmd += url;
cmd += "' -O '";
cmd += filename;
cmd += "'";

Note that, if the user can specify "url" or "filename", you have to pay attention to their values to not introduce a command execution vulnerability.

Another tool to look at might be "rsync".

Share this post

Link to post
Share on other sites
Thanks for the tips.

I forgot to tell that the transfer has to be asynchronous. I have to be able to cancel it as well, if it is in progress. So it seems cannot use wget.

libcurl-multi seems to be the thing I was searching for, as I can combine curl's internals with my own select() routine.
Going through documentation right now...

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