Saturday, August 29, 2015

Create a simple server with current directory's content using Python SimpleHTTPServer

When using Linux in a network environment you may want to get some files in one computer to another. Python's SimpleHTTPServer is a great tool which can be used to serve the contents of the current directory from the command line.

You just need to go inside the relevant folder using command line and give the following command.
This will start a server in port 8000 in your machine which hosts the contents of the current folder.

python -m SimpleHTTPServer

Then you can download the files from another machine using the curl command as below.

curl http://:8000/file-name.extension > file-name.extension 

Here's another way of making the current directory an http server with ruby

ruby -run -e httpd -- --port=8000

[1] https://docs.python.org/2/library/simplehttpserver.html

No comments: