SimpleHTTPServer with Python

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

SimpleHTTPServer with Python

Postby lik » Fri Apr 29, 2011 9:53 am

Sometimes it can be very handy to download/navigate some files from the server without altering current web server configuration or setup of additional services.
Python default module SimpleHTTPServer allows to do it very easy:
Code: Select all
cd /home

Code: Select all
python -m SimpleHTTPServer

Serving HTTP on 0.0.0.0 port 8000 ...
localhost - - [29/Apr/2011 12:28:33] "GET / HTTP/1.1" 200 -
localhost - - [29/Apr/2011 12:28:33] code 404, message File not found
localhost - - [29/Apr/2011 12:28:33] "GET /favicon.ico HTTP/1.1" 404 -
localhost - - [29/Apr/2011 12:28:34] "GET /dir/ HTTP/1.1" 200 -

If the directory has a file named index.html, that file will be served as the initial file. Otherwise directory listing will be displayed.
Default listen port/interface can be set as:
Code: Select all
python -m SimpleHTTPServer 8080 192.168.1.1


For Python 3.x:
Code: Select all
python -m http.server
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to Linux specific