Sunday, December 18, 2016

How to use SimpleHTTPServer


Prerequisite:- 

Linux flavor OS
python installed

What is SimpleHTTPServer :-

The SimpleHTTPServer module that comes with Python is a simple HTTP server. The SimpleHTTPServer provides standard GET and HEAD request handlers. With SimpleHTTPServer you can turn any directory in your system into your web server directory.

If you installed python, you don't have anything to install or configure. It is built in HTTP server with python.
If you don't install python use below apt-get command to install it first,

sudo apt-get install python

How to use it :-

Start the server by using below command (which is start with default HTTP port- 8000),

python -m SimpleHTTPServer

If you need to start the server by specifying the port. You need to used below command format,

python -m SimpleHTTPServer [port]
Sample command below,

python -m SimpleHTTPServer 8085

 How to share a directory and files :-

First you need to cd (change directory) as you wish.

$ cd /home/pradeepa/shareDirectory/

Now you can start the SimpleHTTPServer in current directory and wish to have access via browser,
/shareDirectory $ python -m SimpleHTTPServer 8085

Just after hit enter you can see below massage,
Serving HTTP on 0.0.0.0 port 8085 ...

Click your favorite browser and type any of following addresses,

http://localhost:8085/
http://127.0.0.1:8085/
http://your_ip_address:8085/

Now you can listed all the directories and files.

Happy sharing with python  SimpleHTTPServer .

 Reference:-

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

No comments:

Post a Comment