How I sync Android and Ubuntu Music and Photos – wirelessly!

While Android is based on a Linux kernel, lots of the best tools for syncing phones don’t run on the Linux desktop – for my Galaxy S II, Kies Air from Samsung is the default, won’t work. Winamp won’t work, DoubleTwist won’t work…

I want to be able to sync up my phone with my desktop without having to plug in. I want to sync photos and videos from the phone to the computer, and music from the desktop to the phone. I’ve done my research and come up with a method that’s smooth for photos but clunky for music – but it works, so I’ll share it in case anyone else wants to try it.

On the phone side, install PCFileSync. This free app isn’t pretty, but it does what it says – synchronise files with SMB shares (Windows file shares, but we can set them up easily on Linux). Some other apps only sync one way, which is no good to me.

Syncing the photos and videos is simple, so let’s do that first. On your computer, create a folder for the photos to go into – I made one in Pictures called Samsung. Right-click the folder, go to Sharing Options. You may have to set up file sharing before you can do this, but I was already set, so I gave it a name and allowed access to create and delete. That meant I had to change permissions – don’t be scared, anyone connecting will need a username and password already set up on your computer.

Back on your phone, run the app, hit Menu and go to settings. You want ‘Profiles Settings’ and long click to add an SMB profile. Fill in details like a name, then the folder to sync on the handset – /sdcard/DCIM. You’ll need the IP address of your computer – click the network icon and get it from ‘Connection Information’. Fill in a username and password and browse to the shared folder you just set up. Run the sync, you’re good to go.

Now Music is a bit more complex if you’re like me and have loads on the desktop and not enough room for it all on your phone. If you want all you music synced over it’s easy, just like the photos we did earlier.

I have a smart playlist in Banshee (though Rhythmbox does the same) called ‘For Sync’ which I used to sync when plugged in. It basically looks at a ‘not for sync’ playlist and selects everything else – you could also make a random one that selects some stuff to sync over from your whole library, or any other way of generating a playlist. I exported that playlist as an M3U file.

Here’s the complicated bit. In order to sync that playlist to the phone, we need to turn it into a folder structure. We won’t duplicate the files, but link to the original music.

Bring on the bash script! You can download the playlist-links.txt script, then rename it to playlist-links.sh and allow execution in file properties. The contents are at the bottom of the post if you want to check it out before downloading, but I’ll explain it now.

You run the file by typing (at the command line!)
./playlist-links.sh for-sync.m3u – it won’t run without being pointed to a playlist. I’ve not checked that the playlist is of the correct type, so do make sure it’s an m3u file.

The script by default assumes your music directory is in ~/ and that you want the new folders for syncing in ~/Public/ – you can easily change that by editing the script. It starts by asking if you want to clear out any folders and files (links) in the new location. I promise it won’t touch your precious collection, but you have backed up already?…

The script then reads through the file line by line, first making folders if it needs to, then making a (hard) link to the music file in its original location. I found that symlinks didn’t show up in the samba share, so hard links it is.

That’s all it does. Check the outputted file structure and back to the phone. Set up the share as before, this time syncing with wherever you want your music stored. I think it’s best to start from scratch, no music on the phone, in case it makes duplicate files (especially where special characters are involved – I’m looking at you, Ólafur Arnalds!) It takes a while to sync across, a bit longer than over USB, but once you’ve done it once it shouldn’t be bad to add a new album.

Hope that’s of some help. Unfortunately, you’ll need to export the playlist and re-run the script each time you change the music, then sync the phone again, but that might just be the price we pay for running Linux. enjoy!

Update: PC File Sync was corrupting the music that it was transferring, so I’ve tried with AndSMB and FolderSync Lite. FolderSync was the better one, but I’m still finding that it downloads files over and over. That uses a lot of battery and takes ages, so this setup isn’t perfect yet.

Using FolderSync means first setting up an ‘Account’, which means selecting a service – ‘Account type’ (you can choose only one with the lite version), so select ‘SMB/CIFS’, then fill in the IP address, login and password. I like the ‘validate login’ option – it lets you check that the details are correct.

Then you set up ‘Folderpairs’ – one on the phone, one on the server/PC. I think the setup is pretty straight forward and it gives lots of options about how often to sync.

Update 2: I’ve given up for now, I’ve gone back to a normal wired sync with Banshee. FolderSync doesn’t give corrupted files, but it does seem to download almost all the music every time. This takes too much time and battery, so I’ve given up. I continue to sync photos automatically in this way, though with Google+ already doing it for me, I’m not sure that it’s necessary.

 

#!/bin/bash
#PLAYLIST_FILE='/home/jon/forsync.m3u'
NewLoc="/home/$USERNAME/Public/" 	#Folder where the new Music folder will be created
OrigLoc="/home/$USERNAME/"		#Folder where the Music folder currently exists
#read location of saved playlist from user input
if [ "$1" ]
then
PLAYLIST_FILE="$1"
n=0
#remove previously created folders/links (automatically)
read -p "Do you want to remove all old links? (Y/n)" yn
case $yn in
  [Nn]* ) echo "Making links.";;
  * ) echo "Deleting..."; rm $NewLoc/Music -rf; echo "Making links.";;
esac
#read through file line by line
#duplicate folder structure
#hard link files (symlinks don't show up in samba shares)
awk 'BEGIN{FS=" "}{print}' < "$PLAYLIST_FILE" | while read filename;
do
  if [ `echo $filename | cut -c 1` != '#' ]
  then
   folders=`echo "$filename" | awk -F/ 'BEGIN {OFS="/";}{$NF=""}1'`
   mkdir -p "$NewLoc$folders"
   ln "$OrigLoc$filename" "$NewLoc$filename"
  fi
done
else echo "Please choose a playlist file"
fi
  • Hey, I was searching some keywords and found this article. I am syncing my Android over the internet via SSH. I wrote about it on my website: http://glycogen.net/2011/08/02/android-ubuntu-chroot-synchronization-with-linux-using-unison/ Hope it helps you.

  • anake

    good work man, cheers for writing it up

  • anake

    good work man, cheers for writing it up

  • Pingback: Jon Rogers » Backing Up – You Really Shouldn’t Ignore This!()

  • Petko

    To give you a tip : configure your folderpair in foldersync :
    >check md5 sums (faster sync via indexing) 
    >uncheck Always override older versions
    … I think there were one or two more optimizations , that make things perfect.

  • jonrogersuk

    Thanks for that – I might try it all again, especially with the messing around of file systems in ICS.

  • Has this gotten any better over time? I tried something similar using an app called “Syncness” against SMB on my NAS (over wifi), but it was just too inconsistent to use on a regular basis.
    I’ve been on iOS for a year and a half now, will I be positively surprised if I go back to Android now? I’m guessing “no”.

    It’s amazing with all the functionality they cram into Anroid devices these days, that wifi sync isn’t a piece of cake to get working.

  • jonrogersuk

    To be honest it is just set and forget – it just works overnight and there the photos are. I’m not using it to sync any other media to the phone, just from it.