Quick and Dirty File Transfer

Having more computers than limbs introduces the inconvenience of file transfers. Luckily Dropbox et al have put an end to the mess of emailing myself files and carrying flash drives.... Or not! Sometimes I just want to transfer a single file and don't want to clutter up my Google Drive storage. Sometimes I have a multi-gigabyte file and don't want to wait an hour for it to upload to the cloud. Here are some alternate methods for transferring files between computers over the "fast" LAN.

Quick and Dirty Web Server

Python has builtin webserver functionallity. My go to method to transfer a file to my phone when I don't have a USB cable is to set up a temporary web server and browse to it (having a bookmark helps).

$ cd <directory with file>
$ ifconfig                  #take note you your IP address (ipconfig on Windows)
$ python -m SimpleHTTPServer #start webserver on port 8000
$ python3 -m http.server     #python 3 version

The python server is not great - for one thing it is single threaded and completely insecure - but for a single files it's okay. Even for multiple files this can still work. Once before performing an OS update, I backed up a computer by running the python webserver with my home directory as web root and mirroring everything with wget on the other end.

Piping Over Netcat

Given that you're reading this, chances are you know about piping to and from files. Quick refresher: someProgram < fileToUseAsStandardInput > fileToWriteOutputTo. netcat(1) is a handy program that takes whatever you give it and writes it to a TCP stream. There is also a server mode where it reads from a stream and writes to stdout. Using netcat, files can be transfer roughly as follows:

On the destination run:

$ netcat -l 8888 > linear-regression.js
$ sha1sum linear-regression.js
ef138a80a00fc9e7790cf9a95557bf39f1f72ec2  linear-regression.js
$

On the source run:

$ netcat localhost 8888 < linear-regression.js
$ sha1sum linear-regression.js
ef138a80a00fc9e7790cf9a95557bf39f1f72ec2  linear-regression.js
$

Checking the hashes to ensure the file arrived in one piece is probably unnecessary, but does not hurt. For multiple files, just tar/zip them up.

Warning: both of these methods are completely insecure! Make sure to shutdown any servers you start when done. Once I was doing some web development in the library and I noticed in the logs of my temporary server a random request related to Baidu. Be careful what you set as the root web directory because whatever it is will be public. I only use these tricks to transfer pdfs or large media files that are not sensitive.