wiki:ObexFtpExamples

Check and update formatting, then remove this message

ObexFTP usage examples

Directory listing over IrDA

Command:

  obexftp  -l /

Output:

  <?xml version="1.0"?>
  <!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
  <folder-listing version="1.0">
    <folder name="Address book" modified="20020101T002700" user-perm="WD" group-perm="W" />
    [...]
  </folder-listing>

Directory listing over Cable (TTY)

  obexftp  -t /dev/ttyS0  -l /

Directory listing over Bluetooth

Either let ObexFTP do the work and just type

  obexftp  -b  -l

or get the parameters manually

1st Step : discover your phone

  hcitool scan

2nd Step : browse for the reequired channel

  sdptool browse 00:11:22:33:44:55

If there is any service with "OBEX" in its "Protocol Descriptor List" that "Channel" is likely to work.

on Nokia 7650 and Ericsson T68 its channel 10. for Siemens S55 its channel 5.

3rd Step : Perform the transaction

  obexftp  -b 00:11:22:33:44:55  -B 10  -l telecom/devinfo.txt

Getting files from a subdirectory

  obexftp  -c Bitmap  -g happy.bmp

Getting all files from a subdirectory

To get several files, you have to specify each, wildcards will not do:

  obexftp  -c Data/Pictures -g happy1.jpg happy2.jpg happy3.jpg

I have tried different scripts to get all files, but I have ended up with this oneliner for backing up my pictures:

  rm /tmp/mobil.txt; for i in `obexftp  -c Data/Pictures -l`;\
  do name="` echo \"$i\" | grep name | sed 's/"//g' | sed 's/^name=//g' `";\
  echo $name >> /tmp/mobil.txt; done; \
  echo `cat /tmp/mobil.txt|sed 's/\n//g'` > /tmp/mobil2.txt; sleep 1;\
  obexftp -i -c Data/Pictures -g `cat /tmp/mobil2.txt`

Always insert a sleep between calls to obexftp. Some transports can't handle the stress otherwise.

Another way

This script works a little better for me with Irda and Nokia 6230

  #!/bin/sh
  if [ `grep -c -s name /proc/net/irda/discovery` = 0 ]; then
    echo "No irda device connecting!"
    echo "Check and start this script again."
    exit
  else
    device=`grep -o "name.*h" /proc/net/irda/discovery | sed 's/name: //' | sed 's/, h//'`
    echo "Device $device is connecting."
    echo
  fi
  echo -e "Give a name of folder in your mobile: "
  read folder
  echo -e "Give a name of folder you wish to save files: "
  read name
  mkdir ./$name
  cd ./$name
  obexftp -l $folder > /tmp/list_files
  trap "rm -f /tmp/list_files; exit 1" INT
  # You must change line starting with "cat" if does not work with your mobile.
  # For example this work with Siemens S55:
  # cat /tmp/list_files | grep -o "file name=".*"\ c" | sed 's/name="//' | sed 's/" c//' > /tmp/list_files
  # And this is good with Nokia 6230
  cat /tmp/list_files | grep -o "file name=".*"\ s" | sed 's/name="//' | sed 's/" s//' > /tmp/list_files
  sleep 1
  obexftp -i -c $folder -g `cat /tmp/list_files`
  rm -f /tmp/list_files
  cd ..
  echo "Done"

If somebody is more familiar with regular expressions please improve it!

Retrieving some memory info

This is Siemens specific and won't work with any other vendor.

  obexftp  -x 

Simple User Interface for Retrieving Mulitple Files

--- Prabu D (prabu.d at gmail.com) 2006-06-29 09:11

This script works better for Sony Ericsson K500, K500i, K700, K700i series...

Todo:

    Install libxml-xpath, perl and Tk Widgets  
    mkdir MobileFtp; cd MobileFtp;
    Copy the perl script as MobileFtp.pl and chmod +x MobileFtp.pl
    Copy the Tk script as UserInterface.tk and chmod +x UserInterface.tk
    If everything goes well....just run 
    $./MobileFtp.pl
    Select multiple files by pressing Ctrl key, and Click Copy or Delete button
    If Copy is selected, all the files will be copied to the current directory.

MobileFtp?.pl

   #!/usr/bin/perl -X
   use strict;
   use XML::XPath;
   my $file = "/tmp/logt_root";
   system "rm -f /tmp/logt_final";
   print "Initalizing device ......\n";
   system "obexftp -i -x 2>/tmp/null";
   system "sleep 2";
   print "Device ....... ready \n";
   system "obexftp -i -l / > $file 2>/dev/null";
   system "touch /tmp/obex-folder-listing.dtd";
   search($file ,"//folder","/");
   
   system "wish -f UserInterface.tk /tmp/logt_final 0>/dev/null 1>/dev/null 2>/dev/null";
   open(FINAL_FILE1,"< /tmp/logt_final1") or die " can't open File logt_final1 ";
   my $options =<FINAL_FILE1>;
   $options =~ s/\n/ /g;
   my $command = <FINAL_FILE1>;
   close FINALFILE1;
   $command =~ s/\(/\\\(/g; 
   $command =~ s/\)/\\\)/g; 
   $command =~ s/^(\s)*//g;
   $command =~ s/\s$//g;
   $command =~ s/     /@@@@@/g;
   $command =~ s/\s/\\ /g;
   $command =~ s/@@@@@/ /g;
   
   my $temp1 = "obexftp " . $options . $command . "\n";
   
   #system "echo $temp1 >/tmp/logt_1"; 
   print $temp1;
   
   print "Initalizing device ......\n";
   system "obexftp -i -x 2>/tmp/null";
   system "sleep 2";
   print "Processing Files.......\n";
   system "obexftp $options $command";
   print "Deleting temprary files\n";
   system "rm  -f /tmp/logt_*";
   if ($? == -1) {
   print "failed to execute: $!\n";
   }
   print "Done :-))))) \n";
   
   sub search {
   #    print "AUG: " . $_[0] . " " . $_[1];
       print "Scannig Directory " . $_[2] . ".......\n" ;
       my $xp = XML::XPath->new(filename => $_[0]);
       my $temp = ($xp->find($_[1])->get_nodelist);
       foreach my $files  ($xp->find($_[1])->get_nodelist)
       {
   	my $child =  $files->find('@name');
   	system "obexftp -i -l $_[2]//$child > /tmp/logt_$child 2>/dev/null";
   	search("/tmp/logt_$child","//folder","$_[2]/$child");
   	file_search("/tmp/logt_$child" ,"//file","$_[2]/$child");
       }
       return ;
   }
   
   sub file_search {
   #    print "AUG: " . $_[0] . " " . $_[1];
       print "        Scanning Files in " . $_[2] . ".........\n";
       open(FINAL_FILE,">> /tmp/logt_final") or die " can't open haha ";
       my $xp = XML::XPath->new(filename => $_[0]);
       my $temp = ($xp->find($_[1])->get_nodelist);
   
       foreach my $files  ($xp->find($_[1])->get_nodelist)
       {
   	my $child =  $files->find('@name');
   	print FINAL_FILE $_[2] ."/".  $child ."\n" ; 
       }
       close FINAL_FILE;
       return ;
   }

UserInterface?.tk

   #!/usr/bin/wish -f
   set action " " ;
   
   proc LBselect {sellist} {
       global fileSelected
       global action
       set fileSelected "-i "
       append fileSelected $action "\n"
       foreach item $sellist {
   	append fileSelected "     " [.list get $item] 
       }
       
       set Output [open "/tmp/logt_final1" w]
       puts $Output $fileSelected
       close $Output
   
   }
   
   proc setCopy args {
       global action
       set action  "-g"
   }
   
   proc setDelete args {
       global action
       set action  "-k"
   }
   
   scrollbar .h -orient horizontal -command ".list xview"
   scrollbar .v -command ".list yview"
   listbox .list -selectmode extended -width 40 -height 20 -setgrid 1 -xscroll ".h set"    -yscroll ".v set"
   label .label -text "File Selected:" -justify left
   entry .e -textvariable fileSelected
   button .bcopy -text   " Copy Files " -command {setCopy;     LBselect [.list curselection ] ; exit 0 }
   button .bdelete -text "Delete Files" -command {setDelete;     LBselect [.list curselection ] ; exit 0 }
   button .bexit -text   "    Exit    " -command { exit 0 }
   grid .list -row 0 -column 0 -columnspan 2 -sticky "news"
   grid .v -row 0 -column 2 -sticky "ns"
   grid .h -row 1 -column 0 -columnspan 2 -sticky "we"
   grid .label -row 2 -column 0
   grid .e -row 3 -column 0 -columnspan 2 -sticky "we"
   grid .bcopy -row 4 -column 0 -columnspan 2 -sticky "sw"
   grid .bdelete -row 4 -column 1 -columnspan 2 -sticky "se"
   grid .bexit -row 5 -column 0 -columnspan 2  -sticky "news"
   
   grid columnconfigure . 0 -weight 1
   grid rowconfigure . 0 -weight 1
   
   set Input [open [string range $argv 0 end] r]
   while {[gets $Input line] >= 0 } {
       .list insert end $line
   }
   close $Input
   
   bind .list <<ListboxSelect>> {                                                 
       LBselect [%W curselection ]                                                
   }    

Obex PUSH over Bluetooth

Command:

   obexftp --nopath --noconn --uuid none --bluetooth xx:xx:xx:xx:xx:xx --channel <your OPUSH channel> --put <file> 

fetchobex

Fetchobex is a simple Perl wrapper tool that automates the task of copying files from OBEX enabled devices. Minimal documentation and configuration instructions are embedded in the script. Download the script and type:

   perldoc fetchobex
Last modified 3 years ago Last modified on 09/07/11 15:30:30