Author Topic: Quick and easy way of sharing files between computers with Python HTTP Server  (Read 500 times)

0 Members and 1 Guest are viewing this topic.

Offline fiRepath

  • UNIX is very simple, it just needs a genius to understand its simplicity. -- Dennis Ritchie
  • Moderator
  • Chatters
  • Posts: 19
  • Gender: Male
  • Hannibal ante portas
If you need a quick and easy method for sharing files between computers, and you don't want to configure the Apache Web server, or something similar, then Python can help.

Python comes with a built-in module called SimpleHTTPServer or Python 3 http.server that allows you to share any directory on your system, just like a web server directory.
This is especially useful for sharing files between computers within a local network.
For example, suppose you want to share the files inside ~ /shared directory and the local host IP address 192.168.2.100 :
While "shared" can be, any directory on your system.
More info on Python:http://www.python.org/
Source :http://docs.python.org/library/simplehttpserver.html

Code: [Select]
$ cd ~/shared
$ python -m SimpleHTTPServer

The above command will start the HTTP server that serves the port 8000
Then, open a Web browser and enter the following address:

http://192.168.2.100:8000

If you use Python 3, instead of python-m SimpleHTTPServer use the command:

Code: [Select]
$ Python-m http.server
To change the port using the command:

Code: [Select]
$ Python-m SimpleHTTPServer 8080
or

Code: [Select]
$ Python-m http.server 8080
On most Linux distributions Python comes installed by default. Windows users can download it here :
http://www.python.org/download/windows/

Have fun!






The best way to learn UNIX is to play with it, and the harder you play, the more you learn.

Chanops Community