Have you ever needed a way to easily transfer some files to someone or just let them browse through an index of some of the files on your hard drive? It not worth setting up a full fledged enormous web server like Apache or Nginx or Lighttpd. Instead I used to use thttpd to do this. I recently found out how to setup a web server that serves out an index of files from the directory it's run from with a Python one-liner.
python -m SimpleHTTPServer 8080
This line will run a simple web server on port 8080 and serve out an index page of files relative to the current directory you ran the command from. It will check for index.html or index.htm and if found will serve it out. If it's not found it just defaults to serving a directory index. You can read more about the module here
If you wanted serve out files but use https (SSL/TLS) instead then you could do it with OpenSSL. The difference with the OpenSSL web server compared to the Python web server is that OpenSSL will not give you a directory index from the directory you start the server from. You will have to request each file directly. You also need to execute 2 lines to start the OpenSSL webserver. One to generate the web server cert and one to start the server. Still it's very easy.
# Generate the fake cert in the current dir. Press enter to answer all questions. openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem # Start the server on port 4433 (default) using the cert we just made openssl s_server -cert mycert.pem -accept 4433 -WWW
This will serve out files relative to the current directory. Since this is supposed to be quick and dirty the security about it is not that great but the connection is totally encrypted so nothing will be sent in plain text over the connection. With the lines above the key generated is in the same directory that we are serving data from so you should move that to a path outside of the web server. There are a bunch of other options for OpenSSL's s_server. Check out the man page with "man s_server".
I use a firewall to whitelist IP's from trusted people since you can't easily password protect these simple http(s) servers. Just a suggestion.
Del.icio.us! | Digg Me! | Reddit!
This is how to connect to a HTTP server using telnet. All commands are in bold. The [ENTER] below means press the enter key. Note that the enter key always needs to be hit twice after your done typing the last command. The [ENTER] below means hit the enter key.
Connect to the default website.
telnet example.org 80
You should recieve a reply to the effect of:
Trying 192.168.0.1...
Connected to example.org.
Escape character is '^]'.
Now we can send the get command to retrieve a page. Hit the enter key ([ENTER]) twice after the command.
GET / HTTP/1.0
[ENTER]
[ENTER]
Connect to a website that uses virtual hosts.
telnet example.org 80
You should recieve a reply to the effect of:
Trying 192.168.0.1...
Connected to example.org.
Escape character is '^]'.
Now we can send the get and host commands to retrieve a page. Hit the enter key ([ENTER]) twice after the host command.
GET / HTTP/1.1
[ENTER]
Host: www.example.org
[ENTER]
[ENTER]
Connect to a webserver and just get header info.
telnet example.org 80
You should recieve a reply to the effect of:
Trying 192.168.0.1...
Connected to example.org.
Escape character is '^]'.
Now we can send the head command to retrieve a page. Hit the enter key ([ENTER]) twice after the command.
HEAD / HTTP/1.0
[ENTER]
[ENTER]
Del.icio.us! | Digg Me! | Reddit!