You can connect to a remote machine over FTP to download all of its contents, for example to migrate a website or retrieve a backup to your VPS.
To do so we use lftp and its mirror command, which recursively replicates the remote content into a local directory.
If you do not have lftp installed: apt install lftp -y (Debian/Ubuntu) or yum install lftp -y (RHEL/CentOS).
This is the script (replace the host, login, password and destination values with your own):
#!/bin/bash
export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
FTP_HOST='Remote.Server.IP'
FTP_USER='Login'
FTP_PASS='Pass'
BackupDestination='/home/backup'
lftp -e "set ftp:ssl-allow no" << EOF
open ${FTP_HOST}
user ${FTP_USER} ${FTP_PASS}
mirror -e . ${BackupDestination}
bye
EOF
Notes:
mirror -edeletes files in the destination that no longer exist at the source (exact mirror). Remove the-eflag if you prefer to keep what has already been downloaded.set ftp:ssl-allow nodisables TLS; remove it if the remote server supports FTPS so the transfer is encrypted.- You can save the script (e.g.
import-ftp.sh), make it executable withchmod +x import-ftp.shand run it insidescreenortmuxif the download will take a while.