//View Tip #54
Similar Tips
» Counts files in the current directory and subdirectory
» Un-alias a command
» Ignore an alias
» List non-system users
» rc-service alias

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
alias webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'

Want to show something on your machine to someone over the web? Don't copy it or upload it somewhere. Just run "webshare" and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.


View Comments »



Comments 

Add your comment

Comments are currently disabled
AC
This only works on a local network - how can I expose this to anyone via the internet?
Posted 2008-09-27 03:50:35
Akhkharu
I'd guess that you forgot to forward port 8000 to the machine running the 'server'.
Posted 2008-10-03 16:00:20
If you want to use a different port --
Say port '51776'

alias webshare='python -c "from SimpleHTTPServer import test; import sys; sys.argv = [None, 51776]; test()"'

Again, simply type 'webshare' to start listening & serving.
Posted 2008-12-21 17:38:16
masklinn
FWIW, that snipped can be simplified to 'python -m SimpleHTTPServer'
Posted 2009-02-05 15:24:39
Like someone else said, just forward through your firewall/router whatever port this gets spawned on.  So forward port 8000 by default.  then from a remote location type the URL of your server with the port number after the colon as follows >  "http://yourdomain.tld:portnumber";
Posted 2009-04-16 13:35:32
bovorasr
DrMagu's example can be simplified. It simply overrides the command line arguments before running test(). Instead, you can just use the command line arguments regularly:

> python -m SimpleHTTPServer 8080

or, if your python version doesn't support direct execution of a module:

> python -c "import SimpleHTTPServer as s; s.test()" 8080
Posted 2009-05-15 20:30:56
zoom
of course, you have to then forward port 8000 on your router to your computer, and open port 8000 on your computer's firewall. You do run a firewall don't you?
Posted 2009-06-18 18:48:56
h3lp
Serving HTTP on 0.0.0.0 port 8000 ...

Help needed to setup remote server , port fwd is done.
Posted 2009-07-22 19:08:26
Jason
Very cool.  Could have used this on multiple occasions in the past.  Thanks for the info!
Posted 2009-09-24 08:33:14

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit