Hi folks,

I am a beginner in Socket Programming. I am trying to do some simple stuff but had a basic query.

I would like to implement something like wget in C top of a TCP socket (i.e., without using any HTTP libraries). Just provide a URL (Example-- $wget www.foo.com/bar.pdf) on the command line, construct a HTTP GET request to download the file identified by the URL, and download and save the file.

Right now trying this only for static HTTP content.

Can someone point out how to begin? What are the steps involved?

Thanks in advance.

If you are just programming specifically for Linux, I think using os.system() would satisfy your needs.
You would just have to get the string and call the function as such:

import os
url = raw_input('Enter a URL: ') # this would be input() in 3.X
os.system('wget ' + url)

In python you can use urllib2 with open (so it's really high level what you don't seem to want) :

import urllib2
print urllib2.urlopen(url).readlines()

Or you can use the low level socket : http://docs.python.org/library/socket.html and write your own HTTP GET. It's quite easy.

You can do it in C (since we are on the C forum) because it's the same as my last example (only the language change because socket are not language-dependent). If you need an example of HTTP GET you'll find it easily on the web : http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol (see "Example session")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.