Skip to content

Instantly share code, notes, and snippets.

@parkerlreed
Last active March 14, 2024 18:28
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parkerlreed/ebc3c24a08b2d94dd510f502f3d5edd7 to your computer and use it in GitHub Desktop.
Save parkerlreed/ebc3c24a08b2d94dd510f502f3d5edd7 to your computer and use it in GitHub Desktop.
betteradbcopy - Multi-threaded SCP to/from Android device over USB/WiFi with Termux
#!/bin/bash
# Make sure to have OpenSSH setup in Termux as well as setting a password with `passwd`
# Requires https://github.com/upa/mscp and adb platform tools on your local machine
init_sshd() {
adb shell -t "run-as com.termux files/usr/bin/bash -lic 'export PATH=/data/data/com.termux/files/usr/bin:$PATH; export LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so; sshd'"
adb forward tcp:8022 tcp:8022;
}
stop_sshd() {
adb shell -t "run-as com.termux files/usr/bin/bash -lic 'export PATH=/data/data/com.termux/files/usr/bin:$PATH; export LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so; killall sshd'"
adb forward --remove tcp:8022;
}
pull_path="$2"
case "$1" in
pull)
init_sshd
mscp -P 8022 parker@127.0.0.1:"$pull_path" .
stop_sshd
;;
push)
push_path="$3"
init_sshd
mscp -P 8022 "$pull_path" parker@127.0.0.1:"$push_path"
stop_sshd
;;
*)
echo "Invalid option"
;;
esac
@parkerlreed
Copy link
Author

parkerlreed commented Mar 12, 2024

Transferred 50 gigabytes of fairly small files from the phone in just shy of 14 minutes. I plan on implementing push as well, eventually.

(deck@steamdeck 3DLiveScanner)$ ~/Downloads/Packages/mscp.linux.x86_64.static -P 8022 parker@127.0.0.1:/storage/3139-3238/Documents/.Old/ .
Password: 
[====================================================================================] 100% 31.0GB/31.0GB   59.2MB/s  09:23 

(deck@steamdeck 3DLiveScanner)$ ~/Downloads/Packages/mscp.linux.x86_64.static -P 8022 parker@127.0.0.1:/sdcard/Documents/ .
Password: 
[====================================================================================] 100% 19.6GB/19.6GB   74.4MB/s  04:43    

EDIT: Updated with push

@jakibaki
Copy link

ohhhhhh thanksies will sure find use for that sometime

@parkerlreed
Copy link
Author

Comparison with adb push/pull with the same data set

(deck@steamdeck speed_test)$ time betteradbcopy push . /sdcard/speed_test/
8022
Password: 
[====================================================================================] 100% 10.0GB/10.0GB   24.9MB/s  07:12    

real    7m14.266s
user    1m26.889s
sys     1m4.384s
(deck@steamdeck speed_test)$ time adb push . /sdcard/speed_test/
./: 21757 files pushed, 0 skipped. 9.9 MB/s (10749811472 bytes in 1040.715s)

real    17m20.734s
user    0m44.581s
sys     0m10.049s
(deck@steamdeck speed_test)$ rm -rf *
(deck@steamdeck speed_test)$ time betteradbcopy pull /sdcard/speed_test/
8022
Password: 
[====================================================================================] 100% 10.0GB/10.0GB   58.3MB/s  03:04    

real    3m7.590s
user    1m16.308s
sys     1m21.279s
(deck@steamdeck speed_test)$ rm -rf *
(deck@steamdeck speed_test)$ time adb pull /sdcard/speed_test/
/sdcard/speed_test/: 21757 files pulled, 0 skipped. 14.1 MB/s (10749811472 bytes in 726.675s)

real    12m6.696s
user    0m1.944s
sys     0m21.217s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment