Blog available for sell
This blog is available for sale. Please 'contact us' if interested.
Advertise with us
server   0   7164
How to share data between two systems using python simple HTTP server

Consider this, you want to share files between two system or you want to send really large file to your friend or you want to share new season of 'The big bang theory' among your peers.

What if you do not have pen drive with you. What if file size is larger than pen drive capacity? What if you have some file which is required by 100 people?

Python Simple HTTP server comes to the rescue. Using a one line command in your terminal you can overcome all limitations discussed above.



Python Simple HTTP Server:

The SimpleHTTPServer module that comes with Python is a simple HTTP server that provides standard GET and HEAD request handlers. An advantage with the built-in HTTP server is that you don't have to install and configure anything. The only thing that you need, is to have Python installed.


How to start Python Simple HTTP Server:
To start HTTP server on default port, simply type -

python -m SimpleHTTPServer


This will start the HTTP server on default port i.e. 8000. To start the server on some other port, provide the port number with command.

python -m SimpleHTTPServer 8080


This will now list the files and directories in current folder. Go to http://<your_ip_address>:8000  and you will see the list.



How to share the files:

Go to the directory where you file is situated. Lets say you want to share picture in your /home/picture/ directory. Go to /home/picture/  folder and start the server there using above command.

If you have index.html  file in your folder then that file will be served as webpage else files and directories will be listed.

You can access the files on another system by opening the http://<your_ip_address>:8000 url in browser.

Important: Both the systems should be on same network.


Update 1:  Above command is for python 2.x. If you are running python3 then command would be python3 -m http.server .
Thanks to Marek Turnovec.

Update 2:  This http server can handle one request at a time. If you want to setup multi-threaded server, use this github code by Kuldeep K. Rishi.  

How to host Django app for free.
server   0   7164
0 comments on 'How To Share Data Between Two Systems Using Python Simple Http Server'
Login to comment

DigitalOcean Referral Badge

© 2024-2025 Python Circle   Contact   Sponsor   Archive   Sitemap