Instant LAN File Sharing With Python

By | 2009/09/01

The other day I was chatting with a co-worker and he pointed out a very simple command that could be used to quickly and easily share files with people within your LAN. This could also be used to share with people on the internets, but you’d have to configure NAT from your router. That much of the configuration is up to you, but I’ll share with you the quick ‘n easy webshare command.

The only requirement, as far as I can tell, is python. I’ve run it on my Linux machine as well as my OS X machine and it worked just fine with no other configuration or packages installed. It should likely work on anything else that has python installed as well.

To share the contents of any folder on your machine simply run:

python -c "import SimpleHTTPServer; SimpleHTTPServer.test();"

You can run that one-liner anywhere on your file system and then access the files via your browser. Simply point your browser to your LAN IP port 8000 and you should see an index listing of the files.

To make this a little simpler I made it an alias in my .bashrc file. Just add this line somewhere in your .bashrc or .bash_aliases:

alias webshare='python -c "import SimpleHTTPServer; SimpleHTTPServer.test();"'

At this point you can simply run the command webshare anywhere on your file system and share those files. This makes for a really simple tool for sharing files quickly and un-sharing them as soon as you’re done. Just hit ctrl-c to cancel and close the process.

12 thoughts on “Instant LAN File Sharing With Python

  1. angus fraser

    were is the .bashrc or .bash_aliases located?

  2. jheino

    This can also be done in a simpler way:

    $ python -m SimpleHTTPServer
    Serving HTTP on 0.0.0.0 port 8000 …

  3. drewbenn

    In your home directory. They're hidden files (you can tell because the first character is a '.') so they probably won't show up in a file explorer by default.

  4. zelut Post author

    They are located in your home folder. You should be able to edit/find them at ~/.bashrc or ~/.bash_aliases

  5. håkan

    Very sweet tip. (for us clueless l4m3rs…) Thanx a lot!
    (thanx for the rest of the site as well by the way…)

    Works like a charm on karmic as well, but you probably already knew that. Justa saying…

  6. Karthik

    It’s even simpler, actually.

    $ python -m SimpleHTTPServer

    That’s it. I saw it on Command Line Fu a few months ago.

  7. Gigasize

    Phyton is a really good one.. It makes the land sharing so simple and fast.

  8. ngo

    They're hidden files (you can tell because the first character is a '.') so they probably won't show up in a file explorer by default.ngo

  9. Cufflinks

    I’ve run it on my Linux machine as well as my OS X machine and it worked just fine with no other configuration

Comments are closed.