Skip to main content

QuickTip - Run a HTTPServer on Specific location with python

· 2 min read
Strider

Hi, since I have for some time Usbsticks etc to share files have not liked very much I was looking for other ways to provide files conveniently to friends or colleagues at work without the later someone arrives: "can you times, hasste already...".

A small HTTP server that you can easily create on-the-fly no matter what directory or drive you are in.

That's where Python comes in. Python can launch individual modules from the command line. One of the modules is the SimpleHTTPServer. The whole thing is easy to do. You open a terminal and type this command:

python -m SimpleHTTPServer <port>

Break-Down:
-m is a module selection parameter, this parameter expects a module.

SimpleHTTPServer is the module which is assigned to the parameter -m and started afterwards.

<port> is the port number where the HTTP server should be reachable. If you don't specify a port the default port number is 8000.

running.png

The whole thing looks like shown in the picture. If you now simply call http://localhost:8080 in the web browser you will get this view which simply lists the directory.

listing.png

With this little tip, I hope to be able to help further 😄