tips server   0   444
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.
tips server   0   444

Related Articles:
What is the meaning of different aphorism in zen of python
What is zen of python. What is the meaning of zen of python. Explanation of zen of python terms with example. Easter egg Zen of python. import this....
Displaying custom 404 error (page not found) page in Django 2.0
How to create custom 404 error page in Django. Handler404 example Django 2.0. Page not found error in Django 2.0. Custom Error handlers in Django 2.0...
Designing custom 404 and 500 error pages in Django
How to create your own awesome 404 error or 500 error page in django. Step by step guide to help you design your own 404 not found error page in Django. Design your own 500 internal server error page in Django application...
Difference between list, set and tuples in Python and more such comparisons
Difference between tuples and lists, raw_input and input, shallow and deep copy, args and kwargs and other different terms explained in python...

0 thoughts on 'How To Share Data Between Two Systems Using Python Simple Http Server'
Leave a comment:

*All Fields are mandatory. **Email Id will not be published publicly.

Please subscribe to get the latest articles in your mailbox.

Recent Posts:

© 2018-2019