22

I have installed Bluetooth dongle software and with the help of commands (using a terminal), I want to send and receive files from a smartphone.

How can I pair my devices and send files over Bluetooth using Terminal?

Akshay N. Shelke
  • 321
  • 1
  • 2
  • 4

3 Answers3

20

Send files:

bluetooth-sendto --device=12:34:56:78:9A:BC filename

To know your device name (12:34:56:78:9A:BC), you can issue this command:

hcitool scan

Receive files:

Haven't found it yet, but will let you know if it can be done using terminal

edit:

it looks like it can't be done through terminal. Blueman seems to do the trick but it's in GUI

Noosrep
  • 2,124
  • 5
  • 23
  • 41
10

I tested this with Ubuntu Bionic Beaver (18.04) and Android Lollipop.

  1. Ubuntu. Install the needed packages:

    sudo apt install bluez bluez-tools
    

    bluez-tools come with the following tools: bt-adapter bt-agent bt-device bt-network

  2. Ubuntu. Turn on the visibility:

    bt-adapter --set Discoverable 1
    
  3. Smartphone. Scan for remote devices to ID your Ubuntu machine.

  4. Ubuntu. Prep for managing incoming requests interactively with:

    bt-agent
    
  5. Pair devices:

    1. Smartphone. Initiate pairing request;

    2. Ubuntu. Accept the request from the bt-agent screen.

  6. Ubuntu. Send files to smartphone with:

    bt-obex -p [remote_mac] [file]
    

    where [remote_mac] is the mac address of the smartphone. For example:

    bt-obex -p F0:6B:CA:A2:C4:69 ~/book.pdf
    
  7. Receive files from your smartphone:

    1. Ubuntu First create a Bluetooth file (obex) server:

      bt-obex -s [path]
      

      [path] is where to download files. For example:

      bt-obex -s ~/Downloads
      
    2. Smartphone. Send the file;

    3. Ubuntu. Accept the request from the bt-agent screen.
XavierStuvw
  • 1,391
  • 3
  • 14
  • 44
ptetteh227
  • 1,834
  • 14
  • 26
  • 2
    Still, the bt-obex command is non-interactive, asking to type 'y' for each file to be accepted, which can be annoying. However, as it is a command-line tool, you can create a long file `yyy.txt` containing only lines with the y letter, and then run: `cat yyy.txt | bt-obex -s ~/Downloads`. Your computer will accept all files over bluetooth without asking! – dominecf Aug 28 '19 at 20:03
  • 2
    Alternatively, you could use the `yes` command – vcapra1 Feb 03 '20 at 13:38
  • Thanks for this! I also had to install the `bluez-obexd` package. My received files also ended up in `$USER/.cache/obexd/` rather than the specified directory. – Neil Stockbridge May 17 '22 at 05:12
  • I keep seeing `bt-obex: obex service is not found Did you forget to run obexd?` when running `bt-obex` commands. I tried starting it with `systemctl --user` but then it complains that it's already running! – matth Jun 28 '23 at 01:49
1

This works on my computer:

bluedevil-sendfile -u /org/bluez/hci0/dev_<address with underscores instead of colons> -f <file_with_absolute_path>

For example:

bluedevil-sendfile -u /org/bluez/hci0/dev_00_FF_00_FF_00_FF -f /home/tux/test.pdf
shell-tux
  • 11
  • 1