Sharing a Directory Content over HTTP with Python

Sometimes, you need to share some files or directories from your Linux machine in a fast and easy way.

There is no simpler way than …

Using Simple HTTP Server – a module that comes with Python (>= 2.4). In most cases you don’t need to install or configure anything!

It creates a Simple HTTP Server, that turns the current directory into your web server directory, that gives you an opportunity to share files from it over HTTP.

# For Python >=2.4
python -m SimpleHTTPServer
# For Python 3.x
python -m http.server

Now you can access the shared folder by visiting http://your_ip_address:8000.

By default Simple HTTP Server will listen to 0.0.0.0:8000, but port number can be changed:

# For Python >=2.4
python -m SimpleHTTPServer 8888
# For Python 3.x
python -m http.server 8888

0.0.0.0 – means that the server is not bound to a specific address, and will listen on all configured network interfaces.

Was it useful? Share this post with the world!

Leave a Reply