FTP file transfers from/to android

Moderators: kirk, jamesbond, p310don, JakeSFR, step, Forum moderators

Post Reply
user1111

FTP file transfers from/to android

Post by user1111 »

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
user1111

Re: FTP file transfers from/to android

Post by user1111 »

With primitive ftpd ftp server installed/running on the android phone I notice when using Cloud Disk (within Filesystem menu options), for ftp you have to set the port as part of the URL entry, not as separate URL and Port box entries.

viewtopic.php?p=56322#p56322

Image

User avatar
p310don
Posts: 311
Joined: Tue Dec 03, 2019 7:17 am
Location: Brisbane, Australia
Has thanked: 58 times
Been thanked: 93 times

Re: FTP file transfers from/to android

Post by p310don »

I've played with FTP from phone to computer, but always using the web client. Cloud disk is much better. Thanks for the tip!

user1111

Re: FTP file transfers from/to android

Post by user1111 »

Should also be able to use midnight commander (mc) and within that (command line) cd ftp://192.168.43.1:12345/ ... to have a ftp site load as a normal mc folder in the left or right panes, but doesn't work well with primitive ftpd for me (works ok with some other ftp sites).

I'm pretty ok with regular ftp (cli). Busybox's ftpget/ftpput I guess are OK but full ftp is nicer.

I have a linux kernel compiled with rootramfs (initrd) built into that, where that contains just busybox for userland, supplemented with dropbear (for ssh), wpa_supplicant (for wifi) and ftp. 11MB vmlinuz filesize - boots near instantly. I've hard coded my phones ssid within that, so a simple action of turn phones hotspot on (discover is set off, so ssid isn't broadcast) and wifi connect to that from the laptop, and if I start primitive ftpd on the phone I can also ftp into that from the laptop to upload/download files. Whilst ssh (dbclient) enables me to ssh into hashbang for mutt (mail), weechat (irc), elinks/lynx (cli browsers).

Phone as a phone, camera, music/video player, sms ...etc. and also serving as a 'modem' for the laptop to net connect (via wifi hotspot). Laptop for browsing/irc/mail (via ssh into hashbang), where sites see my location as the hashbang servers location and my ISP can't snoop/record other than encrypted ssh traffic flow. Fallback of phones google searching, where using the voice search option (mic in searchbar) is convenient, and/or for displaying web pages that otherwise might be nasty when using a cli browser.

Good for where available bandwidth might be low, 1GB/month data allowance might be way more than enough.

A 11MB (xz compressed vmlinuz, around 30MB non-compressed) 'OS' however is somewhat a spec in the corner of a 4GB ram, 1TB laptop system.

Of course kernel, dropbear ...etc. all build using Fatdog as the tool-chain (devx). And where Fatdog is also the alternative main boot choice (for libre office ...etc.). :thumbup2:

User avatar
rockedge
Site Admin
Posts: 5746
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2023 times
Been thanked: 2110 times
Contact:

Re: FTP file transfers from/to android

Post by rockedge »

@rufwoof Maybe we should compile a pure-ftpd server for Android systems?

user1111

Re: FTP file transfers from/to android

Post by user1111 »

rockedge wrote: Sat Apr 30, 2022 3:57 pm

@rufwoof Maybe we should compile a pure-ftpd server for Android systems?

primitive ftpd is already open source (one branch here ... https://github.com/wolpi/prim-ftpd ) so other than having built the binary oneself (time/effort) that pre-built is good enough for me. Install it via f-droid or side load it via a microSD and you don't even need to touch google/playstore. Only the other day I factory reset my phone and re-initialised without any wifi/data connected, so skipped all of the enter google userid parts. So the phone is a phone (camera, music player ..etc) with hardly any notification interruptions (no blitz of google adverts/products).

user1111

Re: FTP file transfers from/to android

Post by user1111 »

Despite the busybox front page saying 1.35 is current/unstable, the repo has that flagged as stable, so I built that, along with building kernel 5.10 ... that has a projected end of life of Dec 2026 (compared to 2025 for my current 5.4 kernel)

Fatdog devx of course as the tool-chain (devx.sfs) and no patching. I build busybox static, along with dropbear. wpa_supplicant is dynamic (libs) built, a.k.a pinched out of Fatdog, along with ftp. Which together with my ramfs_data.cpio is pretty much the entire 'OS'. Enough to wifi net connect to the phones hotspot for internet connection, transfer files to/from the phone, ssh into hashbang for tmux (mail/irc/etc.) and telnet to BBS's.

For 5.4 to 5.10 kernel transition I noticed that using the default (internal to busybox) inittab didn't work as expected. My /init is pretty basic, just the usual initial mounts followed by a call to busybox init ... that usually invokes /etc/init.d/rcS along with setting up tty's etc. when no /etc/inittab exists. But for 5.10 I've had to drop in a actual /etc/inittab, pretty much the same as the default busybox version, but where I've set it to load /etc/rc.conf instead of /etc/init.d/rcS

That rc.conf is equally spartan, just loads uk keyboard and ter-i32b font.

Odd why that /etc/inittab was needed. But it is quite a few versions jump between my existing busybox and the latest 1.35 version so something obviously changed in that respect.

After a few hours of testing etc. I've used around 4MB of phone data allowance :) A smart terminal of sorts, where sites/google thrusting to install spyware/adverts upon you and run code (javascript) on your box is circumvented. In many respect the old-internet is much more pleasant than the new-internet, leave the new-internet for the phone, and run old-internet + gui office (libre) on the laptop.

Post Reply

Return to “FatDog”