Sonntag, 12. April 2009

Linux: How to copy Files from a Mobile phone over Bluetooth

Hi folks

(No warranty for error free elnglish! :)

I use a SonyEricsson W810i and Linux Fedora10 on a Lenovo 3000 N200 with bluetooth.

So fare so good

What I'd like to to is to copy Files from the phone device to my notebook to backup them.

More concrete, I'd like to copy my almost 600 photos I shot with the on board camera of my device for not loosing them if some when my phone is gone.

Here is the overview of the steps I tried and fixed out:

> A: Mount the mobile phone over bluetooth to my laptop
> B: Copy the files
> C: Compare, if all the files are really transferred


Step A: Mount the device

For this part, there are 2 possibilities:
A1: Using the Bluetooth logo in my gnome system tray
A2: Mounting the device in the bash shell with good old commands

A1: Is almost simple...

By right click on the bluetooth symbol I first have to "setup new device". Following the onscreen instructions adds the device as a new trusted piece.

Next again rightclick on the bluetooth symbol in the system tray and choosing "Browse files on device".

After choosing my device in the list a nautilus browser window opens with my nice device. I can now browse into the folder "Memory Stick/DCIM/100MSDCF" where I find all my photos. The Directory may differ for other manufacturers.

The next step is tricky. I select all the photos on the device and paste them into my destination folder on the hard disk. At the count of almost 600 images, this makes about 215MB. And at the speed of 16KB/s over bluetooth this takes some time as well (more than 1 hour).

Anyway, at the time I did this it was ate in the night already, so I started the transfer and went to sleep.

Unfortunately, I forgot to plug the power adaptor, and it copied only 90% of the images till my laptop went to sleep as well, because the battery was low.

Retrying to copy the remaining files caused some stream errors. I then had to restart the device as well as the computer.
REMARK: If there is a file already in the destination and Nautilus asks me it should replace or skip the file, the stream is lost, which means the device is not yet able to wait for my response and to resume the remaining processes.

So, copy & paste all the files again and selecting skip for the "already exist files" didn't work. But how to compare then the source and destination? I had 2 missing images in the destination. I found out by watching the properties in the folders. But Which ones are missing? I may have forgotten them to mark while I played around at the beginning. stay tuned...

A2: Mounting the device manually

For using more helpful Linux tools like "comm" I need to address the mobile device in the bash shell. Mounting my device works as follows:

***
the following instructions are copied from: http://www.siltala.net/tag/obex/
  • Find out your phone’s Bluetooth MAC address if you don’t know it already:
    hcitool scan
  • Find out the OBEX FTP channel it uses
    sdptool search FTP
  • Load the fuse kernel module:
    sudo modprobe fuse
  • Make a suitable mount point for your phone:
    mkdir ~/Phone
  • Mount
    obexfs -bXX:XX:XX:XX:XX:XX -BYY ~/Phone
    (where XX:XX:XX:XX:XX:XX is your phone’s MAC and YY is the OBEX channel)
  • Unmount when you’re done with your file transfers:
    fusermount -u ~/Phone
In my case, the OBEX channel was "7".

***

nice then, I can use bash shell commands now to handle my files. I mounted the device in ~/w810i.

Step B: Copy the files

As described above, I can use nautilus to copy files. Its also possible to use "cp", but I wanted to see a nice process bar to see how long it takes to complete.

REMARK: It was helpful to switch off thumbnails, because if I open the whole photo folder on my mobile device, it starts to transfer ALL THE IMAGES before I can see them as Thumbnails, which is nonsense at this time, I don't want to wait 2 hours before I select my copy candidates...

After coping the remaining files from last night, as I told, there were 2 files missing in the destination.

C: Comapre, if all the files are really transferred

This is easely done by marking all the photos and opening the properties of that selection "righclick properties". This shows me the number of selected files as well as the total size.
I found out that 2 photos are missing in the destination, very nice, but which ones? I dont like to compare 600 photos by hand ;)

I googeled for the solution I used, here it is:
http://linux.byexamples.com/archives/143/compare-two-directory-listings/


The link explanes "comm" in general, for my purpose I used the following command:

comm -23 <(ls ~/w810i/Memory\ Stick/DCIM/100MSDCF/) <(ls /media/MyBackupMedia/pictures/w810_i_pics/)


Explanations:

> comm usually prints 3 columns, 1: files unique in first file, 2: files unique in second file, 3: files appear in both files.

> The output of "ls" is also interpreted as "file" even it's only the name.

> So I don't want to know which files are unique in the destination (column 2), because no file in the destination is unique.

> I don't want to know which files appear in both files (column 3).

> I want to know WHICh FILES ARE UNIQUE IN THE SOURCE.

> So I remove column 2 and 3 form the output of comm with the option "-23".

> This prints me out the 2 missing files :p

> The characters "<(" are needed and part of the command, "<" sybolizes an input for the command "comm" and the brackets "()" are needed to wrap the path.

Very nice, I found out that picture DSC00089.jpg and DSC00090.jpg were missing. Copying them and my backup is complete *yeah*