How can I connect to my android device to rsync music (or other stuff)?

  • 1
    I recommend editing this to explain exactly what action produced that error message. (For example, if it's the output of a command, you could include the full command.) – Eliah Kagan Sep 9 '13 at 20:39
  • 1
    maybe interesting: Syncopoli – DJCrashdummy Aug 1 '18 at 0:19
  • @DJCrashdummy if you write your comment as answer, I will up-vote it. – guettli Aug 1 '18 at 7:26
  • @guettli i wrote this only as comment, because Syncopoli is just a rsync-client (for now). – DJCrashdummy Aug 21 '18 at 15:54
  • Whatever is the method to run rsync, i recommend to create a hotspot on the machine and connect the Android device to the hotspot. This can drastically increase the synchronization speed. – Alexey Dec 25 '20 at 17:44

Actually using rsync over MTP/usb

It's easier than everyone is saying, first notice that when GVFS mounts the MTP mount it'll be available under. You can force this by opening the phone up in a graphical file-browser (thunar/nautilus/etc)


go in there. Assuming you have one mtp device, this should work:

$ cd /run/user/$UID/gvfs/mtp*

Find where you want to transfer the files too, and then rsync them to it

$ cd SanDisk\ SD\ card/Movies/

$ pwd # prints "/run/user/1000/gvfs/mtp:host=%5Busb%3A003%2C096%5D/SanDisk SD card/Movies"

$ rsync --verbose --progress --omit-dir-times --no-perms --recursive --inplace ~/Videos/ ./

Rsync options

  • --inplace: I highly suggest using --inplace without which mtp may want to copy the file a new, and then rename it to the old one. That may result in copying the file to the SD card twice: once for the mtp transfer to the SD card, and another time because the MTP driver may not support (mv), it may (cp/rm) under the hood to be safe.
  • read man rsync for a description of --verbose, --progress, --recursive but they're pretty self-documenting.
  • --omit-dir-times --no-perms are required because mtp doesn't support that.
  • 3
    I add the following options --omit-dir-times --no-perms --ignore-existing. Rsync fails to set directory timestamps over MTP. I'm pretty sure that "no permissions" is the default, but I like to specify it. Ignoring existing files allows it to pick up where it left off. – Stephen Ostermiller Jul 6 '16 at 12:21
  • 4
    Why --ignore-existing? That's just losing redundancy. You could always --size-only which reduces the sync to the directory listing and not checksums. I'm going to add the --omit-dir-times and --no-perms because that sounds useful, and I seem to recall getting an error at the end about that. – Evan Carroll Jul 6 '16 at 17:41
  • Rsync has problems setting time stamps over MTP properly for me, so without --ignore-existing it tries to sync all the files. I like your --size-only suggestion. I'll try that instead next time. – Stephen Ostermiller Jul 6 '16 at 17:43
  • 3
    I also use put the trailing slash on the destination so I don't have to use a star on the source: ~/Videos/ ./ – Stephen Ostermiller Jul 6 '16 at 17:46
  • 1
    I'm still getting "rsync: open /run/user/1000/gvfs/... failed: Operation not supported (95)" without sudo or "rsync: ERROR: cannot stat destination /run/user/1000/gvfs/... Permission denied (13)" with sudo. Any tips? – Torsten Nov 8 '17 at 20:24

Using sshelper

I found this solution:

  • Install sshelper on the device (no rooted device needed, available from google play market)
  • In my WLAN the device is called "android". But you can use the IP, if you can't give the device a hostname.

Edit local ssh-config, to alter the default port for host "android"

host android
    Port 2222
  • Start sshelper on device.
  • Connect android device to you WLAN.

rsync -rvlc Music android:SDCardLink/

Update I prefere -rvlc to -a since you get a lot of warnings since setting permissions and time-stamps does not work. The option -c makes the second sync much faster.

I prefere -rvl --size-only to -a since you get a lot of warnings since setting permissions and time-stamps does not work. The option --size-only makes the second sync much faster.

Unfortunately it needs some time for music apps to see the new files. Restarting the device helps.

  • 14
    An alternate way to use rsync with SSHelper without having to modify .ssh/config: rsync -avz -e 'ssh -p 2222' Music android:SDCardLink/ (stackoverflow.com/a/4630407/399105) – bmaupin Jan 20 '14 at 4:08
  • 1
    @guettli what for -c checksum option to syncing music files ? this can slow down significantly – EdiD Feb 14 '16 at 14:32
  • 5
    @guettli from rsync man : -c, --checksum. Without this option, rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver. This option changes this to compare a 128-bit checksum for each file that has a matching size. Generating the checksum means that both sides will expend a lot of disk I/O reading all the data in the files in the transfer, so this can slow things down significantly. – EdiD Feb 23 '16 at 8:21
  • 4
    @guettli I guess that --size-only would be the fastest solution. However it's not so save as -c – niels Dec 22 '16 at 19:51
  • 2
    I used USB tethering and got much faster transfers. The following command worked for me after I ran SSHelp and it showing IP which might be different everytime: rsync -avzhP --inplace --info=progress2 -e 'ssh -p 2222' /home/username/path/to/pics/ – Organic Addict Dec 25 '16 at 12:03

rsync backup for Android can be configured to sync in reverse, that is from a Linux host to Android device.

And with the help from LlamaLab Automate one can configure the Android device to rsync automatically on specific conditions, e.g.:

  1. at 5 am,
  2. when the phone is connected to a specific Wi-Fi, and
  3. when it is charging.

I was looking for a solution to rsync FROM android to NAS for images backup.

Grsync, graphical version of rsync, worked just fine.

Fortunately, it also can rsync TO android. The only problem -- it can not preserve time stamps so all transferred files will have time stamps of the moment they were rsynced.

    sudo apt install android-file-transfer
    sudo apt-get install grsync

It seems that -a key I was using in the command line to rsync from android does not work with mtp: when I check "preserve permissions" and "preserve owner" and "preserve group" in grsync no file is transferred. Default grsync settings "preserve time", "Verbose" and "Show transfer progress" just works.

While rsyncing to android -t key should be ommited: files will be transferred but rsync will give errors on not preserving time stamps.

Grsync output for command line FROM android:

    rsync -r -t -v --progress -s /run/user/1000/gvfs/mtp\:host\=%5Busb%3A001%2C013%5D/Micro\ SD/test /home/FREENAS/

Grsync output for command line TO android:

   rsync -r -v --progress -s /home/FREENAS/test /run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C013%5D/Micro\ SD/

where run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C013%5D my android phone mount point.


Using Termux

Termux brings a whole lot of Linux command line utilities to Android, including rsync and openssh.

You can set up an SSH server on your Android device, then use rsync over SSH, provided both your PC and your Android device are on the same WLAN connection.

The Termux Wiki clearly explains the steps required to set up SSH and use rsync.

To sum up:

  1. Set up Termux

    • Install Termux
    • Grant Termux filesystem access (Storage permission) from Android settings
    • Open Termux
    • Set up a password
      $ passwd
      New password: 
      Retype new password: 
      New password was successfully set.
    • Update the list of packages
      $ apt update
    • Optionally, upgrade the existing packages as well (this solved a compatibility issue in my case)
      $ apt upgrade
  2. Set up openssh

    • Install openssh
      $ apt install openssh
    • Start the ssh daemon
      $ sshd
      It listens on port 8022 by default.
  3. Install rsync

    $ apt install rsync

To get started, all you need is:

  • Your username on Termux
    $ whoami
  • The IP address of the Android device
    $ ip -4 a | grep wlan0 | tail -1
        inet brd scope global wlan0
    which, in this case, is

Now, you can do pretty much anything with rsync. For example, if you wish to copy the ~/Music directory from your PC to the Android device's /sdcard, you could do something like:

$ rsync -e 'ssh -p 8022' -aP ~/Music u0_a223@

When prompted for a password, enter the one you set earlier.


None of the above did quite what I was looking for. Specifically part of the OP's question: how do I rsync my music to my Android phone? Well, I took parts of the suggestions from these answers and wrote my own Bash script:


echo "Starting rsync with Android."

dst_dir="/run/user/$UID/gvfs/mtp:host=OnePlus_HD1925_SERIAL/Internal shared storage"
rsync --progress \
      --human-readable \
      --omit-dir-times \
      --no-perms \
      --recursive \
      --inplace \
      --size-only \
      --exclude='*.jpg' \
      --exclude='*.JPG' \
      --exclude='*.jpeg' \
      --exclude='*.JPEG' \
      --exclude='*.png' \
      --exclude='*.bmp' \
      --exclude='*.txt' \
      --exclude='*.pdf' \
      --delete \
      "$src_dir" "$dst_dir"

echo "rsync operation is done. Enjoy the music :)"

I just dropped this in ~/.local/bin where I've got other scripts (your system's default PATH should actually already have this directory). You just have to make sure that File Transfer is on and that the storage is actually mounted before you run it. Nothing bad will happen if you don't: rsync will just yell at you.

This script:

  • Takes into account that Androids can't retain ext4 style metadata on files
  • really is faster than the other options in my experience, using size-only
  • Excludes album covers and scans from flooding your phone's file system :)
  • Really syncs! It deletes stuff when you delete from the source, like fixing song metadata and replacing it with the correct file instead of keeping two copies.

Also, if you choose this answer specifically because you like the --exclude tags, you might also need a way to do clean-up on your phone if it already synced a whole bunch of unwanted images:

# Remove all *.jpg and *.JPG from the current directory, recursively.
find . -iname *.jpg -exec rm {} \;

I know that the OP wanted to use rsync, but if the idea is to sync directories, I strongly recommend using syncthing. Many, many, benefits:

  • it will run continuously, no need to fire it from time to time;
  • it will sync many different folders, to many different devices, at the same time;
  • you can use syncthing as part of a backup solution for your cellphone, in two steps: (1) you sync all important data from your cellphone to an external host (2) you setup a backup solution on that host.

I personally sync all important data from any device I own to at least another device, possibly two, located in physically different places; at least one of these devices has raid disks; I then add snapper to one device, so that old versions of all files are kept; or you can use a feature of syncthing to accomplish the same results.

One last note of warning. If you run out of space on one device, that device will stop syncthing, but you will not get any error from it, so you should check from time to time. If you use snapper it is quite easy to fill up disks, caveat emptor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.