Here's a test script I've just run/tested that works for me.
Home network is a ISP media box/router that I attach to via wifi using wlan0
Android phone, with a FTP client installed, that has hotspot set/created/enabled.
Using FTP to transfer files to/from a shared/common folder (/mnt/sda2/ftp)
Fastest wifi based transfer (better for large files) is when we set the phone to be a hotspot, connect to that from Fatdog, run a ftp server on Fatdog and connect to that from the phone. I get around 50Mb transfer speeds that way. A form of peer to peer wifi connection. Phones wifi doesn't even have to be connected, nor data.
But that means having to disconnect my laptops network from the main home router, to set up a connection to the android, ... do the ftp'ing, and then reset the laptop network back to the main router again.
When you connect using wpa_supplicant the record of that connection is dropped into /etc/wpa_supplicant.conf, going through connecting to both the main router and the phone I grabbed copies of those wpa_supplicant.conf files, and dropped them into the following script (ssid and ssid passwords have been changed before posting here).
It uses wpa_supplicant priority to depict which of the two wifi's to connect to according to whether the script was passed a parameter of 'android' or not
# myscript android ... for instance if the script is named 'myscript'. When android is passed as a parameter it wifi connects to the phones hotspot, and initiates a ftp server session on the laptop, so all ready to start ftp'ing files thereafter from the phone using whatever ftp client was installed on the phone from PlayStore (I opted for WM FTP). Once done then just run myscript again to reset the network back to a main router connection, so that the laptops back online.
Does conflict with the Fatdog tray network icon - which shows no connection once the script is run, but for me at least the network is actually connecting/working.
Purely posted as a possible guide of how flipping between different wifi connections might be achieved via a script Not tested other than 'it works'. Fundamentally involves three elements, /etc/network/interfaces in which interfaces are defined and where in this case we use the id_str as the wpa_supplicant interface name association. wpa_supplicant and its /etc/wpa_supplicant file - that does the association. udhcpc that sets up the IP and dns against that associated interface. Oh and a 4th element of a ftp server run using tcpsvd rather than setting it up as a inet service.
Code: Select all
#!/bin/sh
# Rufwoof April 2022
# Using wpa_supplicant, so ...
# default priority = 0, higher the number the higher the priority
# We set our home router wifi at a fixed 10 level, so if
# ANDROIDPRIORITY is set to less than 10 we connect to our home router
# if greater than 10 then we connect to our android phones hotspot
# (assuming all are enabled/available)
if [ "$1" = "android" ]; then
ANDROIDPRIORITY=20 # if 'android' parameter connect to android hotspot
else
ANDROIDPRIORITY=5 # else connects to home router wifi
fi
killall wpa_supplicant
killall tcpsvd
killall udhcpc
rm /var/run/wpa_supplicant/wlan0
cat <<EOF >/etc/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=users
update_config=1
p2p_disabled=1
network={
ssid="No_Network"
key_mgmt=NONE
auth_alg=OPEN
}
network={
ssid="my home ssid"
psk="ssidpassword"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
id_str="home"
priority=10
}
network={
ssid="Xperia"
psk="password"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
id_str="android"
priority=$ANDROIDPRIORITY
}
EOF
# id_str .. same value used above as in /etc/network/interfaces
cat <<EOF >/etc/network/interfaces
iface lo inet loopback
iface home inet dhcp
iface android inet dhcp
EOF
wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf &
udhcpc -i wlan0
# if we're setting up android as our hostspot/connection
# then assume we want to transfer files and initiate a ftd server
# for that on /mnt/sda2/ftp
if [ "$1" = "android" ]; then
mkdir /mnt/sda2/ftp
chmod a+wrx /mnt/sda2/ftp
tcpsvd -vE 0.0.0.0 21 ftpd -w /mnt/sda2/ftp
# We use tcpsvd otherwise it has to be a inet
# w allows upload
# requires tcpsvd to have been built into busybox
# On android .. install a ftp client
fi