-
-
Save parkerlreed/ebc3c24a08b2d94dd510f502f3d5edd7 to your computer and use it in GitHub Desktop.
#!/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 [email protected]:"$pull_path" . | |
stop_sshd | |
;; | |
push) | |
push_path="$3" | |
init_sshd | |
mscp -P 8022 "$pull_path" [email protected]:"$push_path" | |
stop_sshd | |
;; | |
*) | |
echo "Invalid option" | |
;; | |
esac |
Termux on phone, openssh installed, password set and termux-setup-storage has been run
[unawesomeguy@unawesomepc unawesomeguy]$ bash -x ./betteradbcopy pull /sdcard/
+ pull_path=/sdcard/
+ case "$1" in
+ init_sshd
+ adb shell -t 'run-as com.termux files/usr/bin/bash -lic '\''export PATH=/data/data/com.termux/files/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files (x86)/Eclipse Adoptium/jdk-8.0.322.6-hotspot/bin:/mnt/c/Program Files (x86)/Eclipse Adoptium/jre-8.0.322.6-hotspot/bin:/mnt/c/Program Files (x86)/Eclipse Adoptium/jre-11.0.14.101-hotspot/bin:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/OpenJDK/openjdk-8u312-b07-jre/bin:/mnt/c/Program Files/OpenJDK/openjdk-11.0.13_8-jre/bin:/mnt/g/Util/A/platform-tools:/mnt/c/Program Files/dotnet/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/g/mmm:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files (x86)/ZeroTier/One/:/mnt/c/Program Files/nodejs/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files/gsudo/Current:/mnt/c/Program Files/WireGuard/:/mnt/c/Users/unawesomeguy/AppData/Local/Programs/Python/Python310/Scripts/:/mnt/c/Users/unawesomeguy/AppData/Local/Programs/Python/Python310/:/mnt/c/Users/unawesomeguy/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/unawesomeguy/AppData/Roaming/npm:/mnt/c/Users/unawesomeguy/Desktop/SillyTavern - Copy/TavernAI-extras/ss; export LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so; sshd'\'''
bash: syntax error near unexpected token `('
+ adb forward tcp:8022 tcp:8022
8022
+ mscp -P 8022 [email protected]:/sdcard/ .
Password:
stat: /sdcard/ Permission denied
total 0 byte transferred
+ stop_sshd
+ adb shell -t 'run-as com.termux files/usr/bin/bash -lic '\''export PATH=/data/data/com.termux/files/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files (x86)/Eclipse Adoptium/jdk-8.0.322.6-hotspot/bin:/mnt/c/Program Files (x86)/Eclipse Adoptium/jre-8.0.322.6-hotspot/bin:/mnt/c/Program Files (x86)/Eclipse Adoptium/jre-11.0.14.101-hotspot/bin:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/OpenJDK/openjdk-8u312-b07-jre/bin:/mnt/c/Program Files/OpenJDK/openjdk-11.0.13_8-jre/bin:/mnt/g/Util/A/platform-tools:/mnt/c/Program Files/dotnet/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/g/mmm:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files (x86)/ZeroTier/One/:/mnt/c/Program Files/nodejs/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files/gsudo/Current:/mnt/c/Program Files/WireGuard/:/mnt/c/Users/unawesomeguy/AppData/Local/Programs/Python/Python310/Scripts/:/mnt/c/Users/unawesomeguy/AppData/Local/Programs/Python/Python310/:/mnt/c/Users/unawesomeguy/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/unawesomeguy/AppData/Roaming/npm:/mnt/c/Users/unawesomeguy/Desktop/SillyTavern - Copy/TavernAI-extras/ss; export LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so; killall sshd'\'''
bash: syntax error near unexpected token `('
+ adb forward --remove tcp:8022
I guess it doesn't expect to be ran on WSL2 but I don't understand why permission is denied. I tried passwd
only and passwd parker
. I'm also connecting adb using WiFi.
You need to escape the path in the adb command. Mine was pulling in the computer path as well, but because it was all Unix, it didn't mess with it.
files/usr/bin/bash -lic 'export PATH=/data/data/com.termux/files/usr/bin:"$PATH"; export
It's either double or single quotes I don't recall exactly.
Worst comes to worse. I guess it's not really needed since mine was all garbage too.
files/usr/bin/bash -lic 'export PATH=/data/data/com.termux/files/usr/bin; export
That solved one problem but stat: /sdcard/ Permission denied
is still an issue.
And you can list the SD card within termux directly?
Only thing I can think of is maybe try removing the trailing forward slash.
pull /sdcard
I can cd into sdcard and make it show the files. I tried what you suggested and it's just the same.
Ok this must be something new with Android 14. I'm seeing the same error here. I can list in Termux but not over the adb shell termux wrapper or SSH.
I'll let you know if I get it working.
In the meantime, the proper fix for path is \ escaping the $
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; bash'"```
Thanks for the script, transferring my photos/videos with 250MB/s now. Much better than mtp.
That solved one problem but
stat: /sdcard/ Permission denied
is still an issue.
But you did give Termux access to files right? :P
I've figured out the solution. The way to correctly allow permissions is to disable files permission, termux-setup-storage, enable files permission and it would work.
Could this be made to work with specific files in a folder? I kind of don't want to do a one large file transfer
So you have Termux on the phone, OpenSSH installed, password set, and granted storage?
termux-setup-storage
Not sure why the adb invocation is producing the unexpected token.
After verifying everything above post your output for
So we can get an idea of what is being built out as it's running.