Clicky

20230403

Building an FTP server: from zero to hero in less than 3 minutes

Requirement: a simple FTP server, low on energy and with cheap hardware. This is my IPcam streams- and snapshot server.

A secondhand Archer C7 is available for (less than) $10 or even for free. Check your attic or eBay for compatible hardware. Make sure you have the 12VDC/2Amp power supply. You have to figure out how to put OpenWRT on the Archer C7 (or on other compatible hardware. Note: minimum 16MB flash memory is required). There are excellent webpages ready to teach you how flash a router with  OpenWRT firmware.


TP-Link Archer C7 + USB disk

FTP server build steps:

  1. Install FTP server and disk management software;
  2. Configure the USB disk;
  3. Configure the FTP server.

Prerequisites:

  1. Put OpenWRT on the Archer C7;
  2. Make sure:
    • That the router has Internet access;
      Tip: configure the Archer C7 WiFi adapters as a WiFi Client (Network > Wireless > Scan > Join Network > WPA passphrase > Submit > Save > Save & Apply);
    • The USB disk is attached to the C7;
    •  Computer to connect to the C7, to show the OpenWRT webpages and an SSH client (e.g. putty).

This is the webpage you need to see, to get started:

All done? Here we go:

Logon to the Archer C7 (SSH client, e.g. putty) and install the software. Copy the script below and paste the next lines in your Putty session. You will see command responses.

WARNING: you WILL lose data on the USB disk, even if you do not want that. Don't blame me, you are on your own!  

#--- FTPserver20230428

sleep 1
clear

#--- Script start.

#--- Check Internet connectivity...
ping -c 4 9.9.9.9

#--- Update list of available software...
opkg update

#--- Install all software and prepare disk partition...
#--- USB support...
opkg install kmod-usb-storage kmod-usb-storage-uas usbutils
#--- Storage support...
opkg install block-mount e2fsprogs f2fs-tools kmod-fs-f2fs kmod-fs-ext4 sgdisk
#--- FTP server...
opkg install vsftpd
#--- User account management...
opkg install shadow-useradd
 
#--- Prepare harddisk/SSD/USB disk...
lsusb -t
block info | grep "/dev/sd"
sgdisk -o /dev/sda
sgdisk -N 1 /dev/sda
sgdisk -p /dev/sda
sgdisk -c 1:FTPstorage /dev/sda
sgdisk -i 1 /dev/sda

#--- Create filesystem (choose one)...
#--- USB stick/SSD...
# echo y|mkfs.f2fs /dev/sda1

#--- Harddisk...
echo y|mkfs.ext4 /dev/sda1

#--- Mount the disk automatically after reboot of the Archer C7...
block detect | uci import fstab
uci set fstab.@mount[-1].enabled="1"
uci commit fstab
uci set fstab.@global[0].check_fs="1"
uci commit fstab

#--- Mount the disk now...
block mount
mount | grep "/mnt/sda1"

#--- Create the FTP account and set the password...
useradd -r -s /bin/false -d /mnt/sda1/ftp ftpuser
passwd ftpuser -d
mkdir /mnt/sda1/ftp
chown ftpuser /mnt/sda1/ftp
ls -al /mnt/sda1

#--- Create FTP server configuration file...
echo "
background=YES
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
check_shell=NO
local_root=/mnt/sda1/ftp
session_support=NO
" > /etc/vsftpd.conf

#--- Restart the FTP server and check if the FTP server is running...
/etc/init.d/vsftpd restart
ps | grep ftp

#--- Create scheduled task to remove FTP files older than 30 days...
echo "#--- At midnight, delete files older than 30 days...
0 0 * * * find /mnt/sda1/ftp -type f -mtime +30 -exec rm -rf {} \;"| crontab -

#--- Set hostname...
uci set system.@system[0].hostname=FTPserver
uci commit
echo $(uci get system.@system[0].hostname) > /proc/sys/kernel/hostname

#--- Set FTP user password...
passwd -a sha512 ftpuser
 

That's all. It takes ~3 minutes to build this configuration.

Hardening:

  • You might need to configure the "LAN" interface to a fixed IP address on your network, so that the FTP server can be accessed by other devices on your network. Connect the Ethernet cable to port LAN1;
  • There is NO security on this FTP server. Anyone that knows the FTP client username/password can access the FTP server files. Username and password will go unencrypted over the network.We can prevent that the FTP server has Internet access: set the Default Gateway to 127.0.0.1 or a not used IP address in your home network;
  • Set a password for the root user (System > Administration);
  • Remove the WiFi client settings (Network > Wireless > Remove).

Performance: 

Upload speeds of ~10Mb/s (to a USB thumb drive) or ~19MB/s (2.5" hard disk)  are possible. 

Energy:

An Archer C7 with a USB hard disk consumes between 4.4W (in rest) and 6W (busy).

Build console output:

 To test the server, you can use Filezilla to connect to the FTP server and test upload/donwnload/delete:



 

78:5A:F1:DC:BC:7D:14:0B:C3:F5:14:8C:FB:DF:7E:FD:7F:9C:7C:F9:BA:AA:84:0C:52:48:30:01:25:38:65:FC

Real Time Web Analytics