Tuesday, January 15, 2008

One easy way to transfer files with Gnome

Transferring files from one person to another can be a frustrating process. E-mail won't work for files that are too big; using instant messenger can be problematic if you're using two different clients or someone has a firewall; using something like yousendit is very annoying, etc.

One foolproof way is to use an http server (like apache) and hard link the file you want to send into your apache directory and then send a link to the person. This will work, but it is kind of cumbersome.

If you're using nautilus however, you can install the nautilus-actions plugin (you can get it in ubuntu with sudo apt-get install nautilus-actions). This plugin allows you to add stuff to the right click context menu. Once you have it installed, under Gnome, it should appear under System->Preferences.



In this case, I created an action that uses bash to call a shell script with the argument of the full path of the selected file. (my script is in my home folder, but obviously it can be wherever you want it to be). The Legend button will show you the special variables you can use.

The shell script I wrote is as follows:


if [ -n "$1" ]
then
ln "$1" /var/www/transfer || exit 1 #do the hard link
a=`basename "$1"`
chmod 0744 /var/www/transfer/"$a" || exit 1 #make permissions right
encoded=`echo "$a" | sed -e 's/ /%20/g'` #change spaces to %20
echo http://your_ip_address/transfer/"$encoded" | xclip #copy url to clipboard
fi


It takes the argument of a path to the file, and then hard links it into this folder I created called transfer in my web root (I just did that so that transferred files wouldn't clutter my www root).

Then, it chmods the new link 0777 so that anyone can axess it (ok, it really only needs to be 0700, but whatever).

Then, the spaces are changed to %'sto form a valid url, and the url to the file is put in the X clipboard (if you don't have a static ip, you can write something to get it).

One caveat is that the X Clipboard is kind of weird, you can't ctrl-v from it, instead you must middle click to paste in most Gnome apps... and it will only paste once. I haven't figured out how to put something in the "normal" clipboard, so for now this will have to do.

Now all you have to do to transfer a file to someone is right click on it, select the action you just created, and middle click to paste the url in the IM/e-mail/whatever. Ok, maybe it's not worth it to go through all this trouble, but I thought it was cool...

No comments: