Publish files with a little bit of Termux on Android and on PC - Part 2
12.11.2025
Edited 21.11.2025
- Syncthing
- Termux if using Android or Linux machine
- Server with nginx and Syncthing
I want to share public files that are meant for anyone, and private files that are meant only for a certain person or a group of people.
Therefore I created two folders for Syncthing to share: public_share and private_share and shared these folders with the server with Folder Type as Send Only.
Then I created a few bash functions to use to make copying files to be shared a little easier and also print the URL of shared files. These are for a PC on Linux.
Edit. It's good to automatically add others read permission to the files while uploading. With my nginx settings and user group, uploaded files can't be downloaded otherwise.
# usage: rand-str [len]
rand-str() {
local len str
len=30
if [ -n "$1" ]; then
echo "$1" | grep -qP '^\d+$' || {
echo Argument is not a number >&2
return 1
}
len="$1"
fi
str=$(tr -dc A-Za-z0-9 </dev/urandom | head -c "$len"; echo)
echo "${str}"
}
share-public() {
rsync -aqz --chmod o+r $* /home/jukka/syncthing/public_share/
echo https://fluks.dy.fi/share/public/
}
share-private() {
local dir
dir=$(rand-str)
mkdir "/home/jukka/syncthing/private_share/$dir"
rsync -aqz --chmod o+r $* "/home/jukka/syncthing/private_share/$dir/"
echo "https://fluks.dy.fi/share/private/$dir/"
}
And on Termux the share-public and share-private functions are a litte bit different. rand-str stays the same.
share-public() {
local url
rsync -qaz --chmod o+r --mkpath $* /data/data/com.termux/files/home/storage/public/
url="https://fluks.dy.fi/share/public/"
termux-clipboard-set "$url"
echo "$url"
}
share-private() {
local dir url
dir=$(rand-str)
mkdir "/data/data/com.termux/files/home/storage/private/$dir"
rsync -qaz --chmod o+r --mkpath $* "/data/data/com.termux/files/home/storage/private/$dir/"
url="https://fluks.dy.fi/share/private/$dir/"
termux-clipboard-set "$url"
echo "$url"
}
Then I approved sync requests on the server side and used directories that www server has access to. And I added the following lines to nginx config.
location /share/public/ {
root /srv/;
autoindex on;
autoindex_exact_size off;
}
location /share/private/ {
autoindex off;
}
location ~ ^/share/private/.+/ {
root /srv/;
autoindex on;
autoindex_exact_size off;
}
Both shares are autoindexed but you can't follow links to private shares or guess the path.