How to download photos from phone over bluetooth with ubuntu

I have a samsung sync phone. It is about two years old now. It isn’t fancy, but it has a camera and a bluetooth device.

I wrote a python script to copy photos from my phone to my laptop. Any time I take a bunch of pictures, I just run
$ getpics.py
and if my phone is anywhere nearby, my computer will pull all the photos off my phone.

Bluetooth is a great little tool and I’m surprised it hasn’t caught on more with people like us. I’ve been able to access my phone from my laptop when I’m on the second floor and the phone is across the house and downstairs, still in my work bag. And bluetooth USB dongles are cheap (like around $9). There’s no need for carrying around USB keys or plugging in iPods. Everything should use bluetooth.

The getpics.py script requires that the phone and the laptop have already been bonded with each other. That’s not much work. Put your phone in to discoverable mode, then search for devices with your computer. When you find your phone, punch the same 4-digit PIN into the phone and your computer.

Anyway, here’s the script. I hope it helps somebody out.
#! /usr/bin/env python

# W. Matthew Wilson wrote this script and he released
# it into the public domain.

# vim: set expandtab ts=4 sw=4 filetype=python:

"""
Pull all the images off my phone.
"""

import commands, logging, os

from xml.etree import ElementTree
from xml.parsers.expat import ExpatError

logging.basicConfig(level=logging.DEBUG)

def get_list_of_pictures():

"""
Yield a list of strings, where each string is the file name of a
picture.
"""

# You'll need to change the 00:1D... stuff to your phone's
# MAC address.
# You might need to change /Graphics/ to where your phone
# stores its photos.
status, output = commands.getstatusoutput(
"obexftp -b 00:1D:F6:55:7E:D9 -l /Graphics/")

logging.debug("status of obexftp: %s" % status)

logging.info("Finished running obexftp...")

# Unfortunately, the output from obexftp includes some goofy status
# crap and then some XML data. So I parse each line separately,
# and skip the lines where parsing fails.

for line in output.split('\n'):

logging.debug("About to parse line %s." % line.strip())

try:
x = ElementTree.XML(line)
# Skip lines without a name attribute.
if 'name' not in x.keys(): continue

# Extract and yield the name
photofilename = x.get('name')

logging.debug("About to yield %s." % photofilename)

yield photofilename

logging.debug("Finished yielding %s." % photofilename)

except ExpatError:

logging.debug("This line is not valid XML: %s."
% line.strip())

def grab_pic(photofilename):

"""
Pull the photo named photofilename and save it locally.
"""

# You probably want to change this.
os.chdir("/home/matt/Documents/Photos/phonepics")

status, output = commands.getstatusoutput(
"obexftp -b 00:1D:F6:55:7E:D9 -g /Graphics/%s" % photofilename)

logging.info("Finished storing %s locally." % photofilename)

if __name__ == "__main__":

logging.info("Starting...")

for photo in get_list_of_pictures():
grab_pic(photo)

logging.info("All done!")

17 thoughts on “How to download photos from phone over bluetooth with ubuntu

  1. No problems as I haven't tried out the code yet. When skimming through the code I just noticed an “output.split('n')” which doesn't make sense on line 41.

  2. Great post, what you said is really helpful to me. I can't agree with you anymore. I have been talking with my friend about, he though it is really interesting as well. Keep up with your good work, I would come back to you.

  3. Linux is kind of hard for simple users that like Windows. If you are indeed a Linux advanced user, this article is something that you don't need. If you are a beginner, that is probably too hard for you:))
    __________________________________________
    VoIP Phones

  4. Linux is kind of hard for simple users that like Windows. If you are indeed a Linux advanced user, this article is something that you don't need. If you are a beginner, that is probably too hard for you:))
    __________________________________________
    VoIP Phones

  5. Pingback: Bluetooth applications in GNU/Linux notes | Bugdrome

Comments are closed.