Chiradeep
Chiradeep

Reputation: 991

Can Rsync be used to transfer files from Android client to Linux server programmatically?

I want to transfer abc.txt file from android client to server via rsync. Unfortunately, I did not find any documentation for the same in android developer site. Is there a way to transfer data from the client using rsync in a non-rooted device.

What is the best practice to transfer say 100 MB of data from a client to server? We can always use the Database and make chunk upload out of that. Is there a best practice that is followed apart from Database division and sync design.

Upvotes: 2

Views: 6790

Answers (1)

Danyright
Danyright

Reputation: 426

Do you want a way to achieve this with a script or run it manually from your device ?

Manually, you can do it. The easiest and most reliable is certainly to use rsync - and it works for Linux, MacOS and Windows. And it's also a great way to backup your device :-)

Here are a few simple steps to get there:

  1. Install the Termux app (https://f-droid.org/en/packages/com.termux/)
  2. Open Termux and install the rsync package by typing: $ pkg install rsync
  3. Make sure Termux has storage access permission (you can check in App info > Permissions)
  4. Start using rsync to copy your file(s) from Termux ! $ rsync -av /sdcard/[your-file] [server-ip]:/[destination]

You can the even use it to copy files to your computer with rsync via USB (these are Linux commands, but it should work on any other OS as well).

  1. Activate USB debugging on your device and connect the device via USB to your computer
  2. Open Termux and setup a password: $ passwd
  3. Start SSHD: $ sshd
  4. From your computer type in the shell: $ adb forward tcp:8022 tcp:8022
  5. You can now run rsync from your computer: $ rsync -av -e 'ssh -p 8022' localhost:/sdcard/[whatever-file] /[destination]

Upvotes: 9

Related Questions