Is there a way how to offline safely synchronize directories between sd card on Android which is not rooted and PC with Ubuntu?
Safely = using secured connection between the devices (for example using ssh).
Offline = without Internet access, but the PC and smartphone are connected through LAN.
Synchronize directories = a process which transfers data between smartphone and PC in a way that at the end of the process, both devices contain exactly same data in selected directories (preferably, but not necessarily, excluding filtered files). The process is able to detect deleted data so it doesn't copy file which was originally on both devices and later deleted on one of them.
My systems
- Android 6.0.1 (not rooted)
- Xubuntu 18.04 64 bit PC
What I already tried/checked (without success)
Unison
- https://play.google.com/store/apps/details?id=net.danielroggen.unison
- Problem: requires rooted device.
Unison for Android
- https://play.google.com/store/apps/details?id=com.nerdysoftware.unison
- Not secure - from application description: "No SSH access is necessary - clients connect directly via socket. Because Unison clients connect to your device over a direct socket connection instead of over SSH, the server should only be run when your Android device is connected to a trusted network, like a home WiFi. Running the server on other networks could expose files on your device to untrusted parties."
- Also seems to use older version of Unison (this application requires exactly same versions on server and client to allow data transfer).
Rsync
- https://play.google.com/store/apps/details?id=net.letscorp.rsyncwrapper
- Not quite designated for two-way syncing.
SSHDroid
- https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid
- For using SSH with another software (see bellow)
- Cannot write/modify SD card using the ssh connection. I went to settings -> Applications -> SSHDroid -> Permissions: storage is enabled. There I opened context menu -> all permissions: reading SD card available. Modification/deleting data on SD card available. In other words, I checked the application has permission to modify the SD card: it has.
SSHFS with SSHHelper
- https://play.google.com/store/apps/details?id=com.arachnoid.sshelper
- Same problem as SSHDroid. I checked permissions.
SSHFS with SimpleSSHD
- https://play.google.com/store/apps/details?id=org.galexander.sshd
- Same problem as SSHDroid. I checked permissions.
What I already tried (with mixed/partial success)
Combination: Unison (on PC) + some SSH server (Android) + SSHFS (on PC)
- In case I could find working SSH server; use SSHFS to mount remote Android device locally and then use Unison for synchronization.
- Results:
- When the SSH is actually rw, then it works, but it's so slow that it's impractical - it must ask for every single file and directory over the network. Of course, other apps (like Unison) must do that too, but they don't ask for every single file sequentially (not: client send request for single file - latency - server checks and sends response - client receive response and go to next file).
- Unison requires permission to rename files; it always creates temporary files and directories and when everything is downloaded and double-checked, then old files (if any) are deleted and new files renamed. So if renaming is not allowed, it doesn't work.
SSH/SFTP Server - Terminal
- https://play.google.com/store/apps/details?id=net.xnano.android.sshserver
- This actually works but has two problems;
- It requires entering password several (>10) times when mounted as sshfs (I tried trivial one and and made sure it's not typo) and doesn't support ssh keys. I was able to solve this problem with a hack:
zenity --password | sshfs user@host:/ "$PWD/data" -o reconnect,password_stdin
, but I'm not sure how secure it is. - This ssh is unbelievably slow. Much slower when compared with SSHDroid and SSHHelper (not only with sshfs, but also when I simply connect using ssh and terminal; typing and responses are really, really slow). Maximum speed is 2 MB/s, but most of the time it's ~500kB/s.
- Cannot rename files (permission error) so it makes it unusable with Unison (on PC).
- It requires entering password several (>10) times when mounted as sshfs (I tried trivial one and and made sure it's not typo) and doesn't support ssh keys. I was able to solve this problem with a hack:
Syncthing
- https://play.google.com/store/apps/details?id=com.nutomic.syncthingandroid
- Problem: cannot modify SD card (on non-rooted systems) and devs are not going to fix this anytime soon.
- The only solution is to use obscure, hard-to-reach deep directory structure:
/storage/XXXX-XXXX/Android/data/com.nutomic.syncthingandroid/files
. - But for this particular directory, it works. It's speed is about 5 - 10 MB/s and I suspect that it's being throttled down by SD card itself (or Android). For now, I'm using this solution, but the directory is really inconvenient.
- Smaller problems:
- It doesn't support following symlinks and until someone (other than current devs) implement it, it's not going to be supported.
What problem I'm trying to solve
I "just" want to synchronize data on file level (some pdfs, images, etc.) between my PC and Android smartphone. I use multiple devices (desktop, laptop, etc.) and use Unison (note: I do not insist on this app) to synchronize data between them. Because I switch environment quite offten, I need it to work on one button press and to be fast as possible (which, for example, Unison does greatly). Because I work on different environments, I need to cover my cases: sometimes I'm without Internet access. Other times I'm connected to untrusted network.
This is also reason why I cannot use cloud (like Dropbox): it's slower than two devices communicating directly and sometimes I'm without Internet connection so I cannot synchronize even when the devices are connected on same network.
The reason why I want to sync with SD card is simply because it has bigger capacity so my files fits.