Empty

Total: $0.00

Error message

  • Deprecated function: Array and string offset access syntax with curly braces is deprecated in include_once() (line 20 of /var/www/rugga/it-dan.com/includes/file.phar.inc).
  • Deprecated function: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in include_once() (line 1387 of /var/www/rugga/it-dan.com/includes/bootstrap.inc).
  • Deprecated function: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in include_once() (line 1387 of /var/www/rugga/it-dan.com/includes/bootstrap.inc).
  • Deprecated function: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in include_once() (line 1387 of /var/www/rugga/it-dan.com/includes/bootstrap.inc).
  • Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in include_once() (line 1387 of /var/www/rugga/it-dan.com/includes/bootstrap.inc).
  • Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 395 of /var/www/rugga/it-dan.com/includes/common.inc).

vsFTPd Passive Mode with Dynamic IP

By IT Dan, 06/13/2018 - 17:08

Below is a script that checks the current external IP address, and if it has changed since last check, updates the pasv_address line in the vsftpd.conf file.

I'm using Debian Stretch. For dig you may need to install dnsutils like so:

apt-get install dnsutils

Create the shell script file:

vi /root/vsftpd-pasv_address.sh
#!/bin/bash

[[ -f /root/last_ip.txt ]] && last_ip=$(/last_ip.txt) || last_ip='' # If file exists read value else set empty
this_ip=$(dig +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)
if [ $? -ne 0 ]
then
    # Exit if the dig command failed
    exit 1
fi

# If not empty and IP changed
if [[ -n "$this_ip" && "$last_ip" != "$this_ip" ]]
then
    echo $(date +"%Y-%m-%d %T") "Old IP: $last_ip"
    echo $(date +"%Y-%m-%d %T") "New IP: $this_ip"
    echo "$this_ip" > /root/last_ip.txt
    sed -ri "s/^(pasv_address=*).*$/\1${this_ip}/" /etc/vsftpd.conf
    /etc/init.d/vsftpd restart
fi
exit 0

Make the file executable:

chmod +x /root/vsftpd-pasv_address.sh

I added the following cronjob:

*/10 * * * * /root/vsftpd-pasv_address.sh

The script will run every 10 minutes, and update vsftpd.conf if your external IP address changes.

Category: