Use python as a Simple HTTP Server

The other day, I needed to share files with a Windows based computer. I did not have any ftp nor samba server installed on my machine. For some reason ssh did not work either. As a quick solution, I decided to use a trick I saw some time ago. I started a python process which works as a simple HTTP server. Next, I opened a browser on remote machine and connected to my HTTP server and downloaded the files through HTTP. Here is how I did it. First, I cd into the directory that holds the files I wanted to share

cd ~/mysharedfolder

After that, I started my HTTP server

$ python -m SimpleHTTPServer
Serving HTTP on port 8000 ...

By default, server starts on port 8000. If you need to change the port, you can do it by giving port number to the command as parameter

$ python -m SimpleHTTPServer 8080

In my case, I opened the browser ( firefox :) ) on Windows machine and wrote to address bar ( is the ip address of the machine that I started HTTP server on). I could also reach the server using (localhost) from the same machine that runs the http server.

For more information about SimpleHTTPServer go to documentation.


Here is another one that can serve multiple clients:

python -c "import SimpleHTTPServer, SocketServer, BaseHTTPServer; SimpleHTTPServer.test(SimpleHTTPServer.SimpleHTTPRequestHandler, type('Server', (BaseHTTPServer.HTTPServer, SocketServer.ThreadingMixIn, object), {}))" 9090

blog comments powered by Disqus