Log in

Registration

File Sharing with Python 2.x

Posted: September 28, 2009 / in: Nuts and Bolts / No comments

Python contains a number of web server related modules that provide the basic functionality to serve file system contents by default. So it is very easy to share contents underneath a directory path to all users that can connect your computer via LAN/network.

The following article describes techniques that are available in Python 2.x. For Python 3.x refer to article File Sharing with Python 3.x.

Start Python Web Server

To start the web server from command line simply key in the commands as follows:

1234567891011
# change to the directory that is to be shared$ cd path/mydir # start the web server at port 8000$ python -m SimpleHTTPServer # the following command will do the same trick$ python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" # use this command line for another port number$ python -m SimpleHTTPServer 8080

Attention: Be careful! All contents of the directory tree starting at the current directory will be available to everybody with access to your computer via network!

Request Data

Now you can access your directory contents with web browsers via the Url http://yourserver:8000/. (replace yourserver and 8000 with the ip address/hostname and port number to fit your needs)

python-http-directory

 

Related articles:

Incoming search terms:

© Copyrights and Licenses, 2012 - Linux-Support.com The Professional Linux and OSS Services Portal