Linux Kamarada

How to transfer multiple files between two Android phones without leaving any behind with rsync

If you’ve ever needed to transfer multiple files from one phone to another (e.g. when you boght a new phone), you may have encountered some difficulties. For example, the file manager app crashes before it can list all the files. Or your phone disconnects from your computer in the middle of the copy. Or you compare folders after copying and the number of files does not match.

In these cases, when you want the copy to be done safely and no files left behind, rsync can be of great help. Even though it is a Linux native command line utility, it can be easily installed on Android.

The name rsync is likely an acronym for remote sync. Initially designed to synchronize files between servers, rsync can also be used to synchronize files between personal computers, to synchronize files between folders on the same computer, or, as we will see, to synchronize files between phones.

The difference between a regular file copy and an rsync sync is that rsync compares the folders contents before copying and copies only what’s actually needed. If it’s your first time syncing the contents of one folder to another, and the sync goes smoothly until the end, it’s the same as a regular copy. But if for any reason the sync is interrupted and you try again, rsync picks up where it left off. Even if a file was copied halfway, it copies only the missing half. If, after syncing, you create or modify files in the original folder and run rsync again, it will copy only the new or modified files.

In today’s tutorial, you are going to see how to copy multiple files from one Android phone to another over Wi-Fi using rsync. On the phone where the files are stored, we’ll install a terminal emulator (here, we’ll use Termux). rsync uses SSH for secure file transfer. On the phone that will receive the files, we’ll install an SSH server (here, we’ll use SSHelper).

Before you begin, make sure both phones are connected to the same Wi-Fi network.

Installing the terminal emulator

On the phone where the files are, install the Termux terminal emulator:

Note: depending on your phone, if it is pre-Android 11, the Play Store may inform you that Termux is not supported. In this case, you can install another compatible version of Termux from the F-Droid store or download the APK from GitHub (in this case, to install the APK, you will first need to allow installation of apps from unknown sources).

Open Termux and run pkg install rsync to install rsync:

When asked if you want to continue, type y (yes) and hit Enter:

If you’re already used to the terminal on your Linux computer, Termux is the same thing, the only difference is that it runs on your Android phone.

Tip: typing these commands using the Android touchscreen keyboard can be tricky. If you’d rather use your computer keyboard to type these commands on your phone, give GSConnect a try.

After installing rsync, run:

1
$ termux-setup-storage

This will open an Android screen where you must grant Termux permission to access all files in the internal storage:

Installing the SSH server

On the phone that will receive the files, install SSHelper, the SSH server:

Note that SSHelper isn’t on the Play Store. You’ll need to open its website on your computer and scan the QR code with your phone, or open its website on your phone and tap the download link below the QR code:

You’ll download the SSHelper APK. To install it, you may first need to allow installation of apps from unknown sources.

After installing SSHelper, open it.

When using it for the first time, you need to grant it permission to access storage:

Back to the app, switch to the Configuration tab:

Write down the IP address and port number of the SSH server (in my case, 192.168.15.42 and 2222). Tap the Server Password field and set a password for the SSH server. Restart the app to apply the changes:

Transferring files with rsync

On the phone where the files are, locate them using Termux. To do this, you can use commands like pwd (displays the path to the current folder), ls (lists the folder contents) and cd (changes the current folder):

Similarly, on the phone that will receive the files, switch to the Terminal tab and locate the destination folder. You can use the same commands:

Finally, on the source phone, run the rsync command:

1
$ rsync -e "ssh -p [target_port]" -azzv --no-perms --no-times --size-only [source_path] [username]@[target_ip]:[destination_path]

Where:

  • [target_port] is the port number of the SSH server on the target phone;
  • [source_path] is the path to the files or folder you want to transfer from the source phone;
  • [username] is the username to connect via SSH to the target phone. Here, you can type anything, as SSHelper does not validate this information;
  • [target_ip] is the IP address of the target phone; and
  • [destination_path] is the path on the target phone where you want to save the files.

Example:

1
$ rsync -e "ssh -p 2222" -azzv --no-perms --no-times --size-only Camera/* kamarada@192.168.15.42:/data/data/com.arachnoid.sshelper/home/SDCard/DCIM/Camera/

Synchronization with rsync begins:

When the sync is complete, check that the files are on the target phone:

That’s it! Enjoy!

Conclusion

If you’ve made it this far, I hope this tutorial has been helpful to you, and that you’ve managed to transfer files from one Android phone to another with rsync, without leaving any files behind.

If you have any questions, please write them in the comments.

If you consider other apps better than those indicated here and/or know another way to safely copy files, without losing any of them, please comment as well.

See you next time!

Would you buy me a coffee?
If you really liked it, if it was really helpful for you, is it worth a coffee? If you want, you can "buy me a coffee" with PayPal or contribute to the project in other ways.

Comments

About

The Linux Kamarada Project aims to spread and promote Linux as a robust, secure, versatile and easy to use operating system, suitable for everyday use be at home, at work or on the server. The project focuses mainly on distribution and documentation.

Ads

Facebook

Author