Home > Internet > Instant LAN File Sharing With Python

Instant LAN File Sharing With Python

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.

If this article has been helpful, please consider linking to it.

Categories: Internet Tags: , , ,

Related Posts

  1. September 2nd, 2009 at 15:26 | #1

    Awesome.

  2. angus fraser
    September 2nd, 2009 at 15:45 | #2

    were is the .bashrc or .bash_aliases located?

  3. jheino
    September 2nd, 2009 at 19:22 | #3

    This can also be done in a simpler way:

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

  4. drewbenn
    September 2nd, 2009 at 22:37 | #4

    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.

  5. September 3rd, 2009 at 16:08 | #5

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

  6. håkan
    September 3rd, 2009 at 17:34 | #6

    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…

  7. September 8th, 2009 at 22:16 | #7

    It’s even simpler, actually.

    $ python -m SimpleHTTPServer

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

  8. September 27th, 2009 at 14:55 | #8

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

  9. September 30th, 2009 at 16:08 | #9

    Hey it did not work in mine??

  10. October 12th, 2009 at 03:48 | #10

    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

  11. October 30th, 2009 at 02:59 | #11

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

  12. November 27th, 2009 at 08:38 | #12

    It just works fine on my ubuntu 9 linux based machine.