Skip to content

Instantly share code, notes, and snippets.

@matasarei
Last active March 18, 2018 18:24
Show Gist options
  • Select an option

  • Save matasarei/a1f4e5cbd18ac112fa182502c0061fb7 to your computer and use it in GitHub Desktop.

Select an option

Save matasarei/a1f4e5cbd18ac112fa182502c0061fb7 to your computer and use it in GitHub Desktop.
Easy way to set up personal home FTP server with OpenWRT (LEDE) router

Easy way to set up personal home FTP server with OpenWRT (LEDE) router

You will need:

  • Router with USB port;
  • OpenWRT or LEDE (recommended) firmware;
  • USB stick or USB hard drive.

Install USB support packages

opkg update
opkg install kmod-usb-ohci kmod-usb2 usbutils kmod-usb-storage kmod-fs-ext4 block-mount
reboot

check USB devices

dmesg | grep sd Output example:

[   12.614343] sd 0:0:0:0: [sda] 61341696 512-byte logical blocks: (31.4 GB/29.3 GiB)
[   12.626964] sd 0:0:0:0: [sda] Write Protect is off
[   12.631918] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[   12.643894] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   12.673730]  sda: sda1
[   12.682703] sd 0:0:0:0: [sda] Attached SCSI removable disk

init proper fstab config

block detect >> /etc/config/fstab

edit /etc/config/fstab

Change target to '/mnt/usb/' and enable automount. Example:

config 'mount'
        option  target  '/mnt/usb/'
        option  uuid    '<your device uuid>'
        option  enabled '1'

Install FTP server

opkg update
opkg install vsftpd

setup FTP dir and access

mkdir -p /mnt/usb/ftp/
chown ftp /mnt/usb/ftp
passwd ftp

Enter any password you like.

edit /etc/passwd

Change /home/ftp to /mnt/usb/ftp. Example: ftp:x:55:55:ftp:/mnt/usb/ftp:/bin/false

configure /etc/vsftpd.conf

Example:

background=YES
listen=YES
anonymous_enable=NO
local_root=/mnt/usb/ftp/
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
user_sub_token=$USER
allow_writeable_chroot=YES
check_shell=NO
port_enable=YES
pasv_enable=YES
pasv_address=<your static ip>
pasv_min_port=32000
pasv_max_port=32127
session_support=NO

enbale Ftp

/etc/init.d/vsftpd start
/etc/init.d/vsftpd enable

configure /etc/config/firewall to provide worldwide access

Example:

config rule
        option name             Allow-FTP
        option target           ACCEPT
        option src              wan
        option proto            tcp
        option dest_port        21
        option dest_ip          <router local ip>

config redirect
        option name             Forward-FTP
        option src              wan
        option dest_ip          <router local ip>
        option dest_port        21
        option proto            tcp
        option src_dport        <any external port you like>
        option target           DNAT
        option dest             lan

config rule
        option name             Allow-FTP-Passive
        option src              wan
        option target           ACCEPT
        option dest_port        32000:32127
        option dest_ip          <router local ip>
        option proto            tcp

config redirect
        option name             Forward-FTP-Passive
        option src              wan
        option dest_ip          <router local ip>
        option proto            tcp
        option src_dport        32000:32137
        option target           DNAT
        option dest             lan

Reboot device after setup (with reboot command). Now you ready to test it.

For local network just use:

ip: <local router ip>
port: 21
user: ftp
pass: <your password>

For worldwide access:

ip: <your external static ip>
port: <external port>
user: ftp
pass: <your password>

Add USB drive idle support (optional)

opkg update
opkg install hd-idle

edit vim /etc/config/hd-idle

config 'hd-idle'
        option 'disk' 'sda'
        option 'enabled' '1'
        option 'idle_time_unit' 'minutes'
        option 'idle_time_interval' '10'

Reboot device after setup (with reboot command).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment