26th April, 2010
You may have seen my post a while back featuring a Python webserver in less than 50 lines of code.
I was tinkering with it a little bit this evening, and decided that I could actually make this pretty useful.
What I’ve done is that if it can’t find what you’re looking for, it dumps out a directory listing with links in it. You will probably be familiar with this kind of behaviour from Apache, nginx etc. (if you don’t turn it off that is), so it’s fairly standard stuff.
I’ve managed to squeeze this into just 70 lines of code, so it’s pretty lightweight.
A couple of points to note from this little exercise:
So in short, this server now supports directory listings, and serving things other than HTML.
There was one more thing I wanted to do though. I have been toying around with the Android Scripting Environment, which allows you to run all kinds of scripts on your Android phone (in my case, the very shiny Nexus One). So I stuck the pyhon on my phone, ran it, and everything works great! No more needing to mount your phone to your PC just to download some pictures at least!
One word of warning though, the script currently just reads your entire phone, so unless you want people snooping around and having access to every file on your internal and SD card memory, don’t leave it running - this is very much just a proof of concept at the moment!
Here’s my code…