HowTo: Quickly transfer files from an Ubuntu box to another PC over a network without installing Samba, SSH or FTP.
Let’s say you have an Ubuntu PC and a second Windows PC or Mac. You need to do a quick transfer of a file or two from the Ubuntu box, but you really don’t want to go through the hassle of installing and configuring Samba or FTP just for the sake of transferring a couple of files.
Of course you could use a USB flash drive, but it takes twice as long to copy a file that way because you have to copy it to the flash drive and then copy it again from the flash drive to the destination PC. Besides that, what if you don’t have a flash drive big enough to transfer the files you want? Is there a quick and dirty way to transfer some files over a network without the need to install additional software to bridge the compatibility divide?
Indeed there is…
NOTE: This method is not suitable for transferring entire directories of files. While it is possible to transfer multiple files at once using this method, it is primarily intended for the transfer of very small quantities of files due to the fact that you have to initiate the transfer of each file manually – you cannot multi-select files for transfer unless you archive those files into a tarball first.
On the Ubuntu PC, open a terminal and type in the following at the $ prompt:
$ python -m SimpleHTTPServer
If this returns an error when you hit Enter, you are probably using an old version of Python, in which case use the following command instead:
$ python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
When you hit Enter, you should see a message similar to the following:
Serving HTTP on 0.0.0.0 port 8000 ...
What we have done is started a basic mini web server using Python on port 8000 which will now happily serve files from the current directory you started the Python command from! Now open up a web browser on the other PC and, assuming your Ubuntu PC’s IP address is 10.0.0.27, surf to the following web address:
Viola! A full directory listing on the Ubuntu PC is presented that you can now navigate and download files from without needing to install any other software to effect a transfer. Just right-click and save like any normal download link on any ordinary website.
If you started the Python command from your Home directory, then the root of the site starts from your Home directory. If you change to another directory before launching the Python command, the web server will serve files from that directory instead. Standard security rules apply – whatever access your Ubuntu user has will be applied to the Python web server. It is not recommended that you run this command as root.
When you’re done, simply press CTRL+C to stop the Python web server on the Ubuntu PC.
Happy file transfers!
Leave a Reply