Copy files between two remote NAS via FTP
Today's case is very niche and I'm not sure there are many users who need a mini-guide like today's. But this happened to me and now I'll tell you about it.
I recently purchased an older HP N40L Proliant Microserver, on which I installed openmediavault, a Debian-based distribution that allows you to manage your system exactly like a classic headless Linux system, and easily configure shared resources (SMB/CIFS, NFS, FTP, SSH), Docker, oltre i backup, cron routines… and much more.
Now I have to migrate data from the old NAS to this one.
Unfortunately the old NAS is a piece of electronics without great performance. There is space for a disc, an elementary management of SMB shares, is FTP, a DLNA server and a bittorrent manager that I could never get working. The system formats the disk with a filesystem of its own which I have not found information about online and even inserting the old disk into one of the slots on the HP server the disk is recognized, but the filesystem is not interpreted.
Then, i will copy the data between the two network connected devices, even if the old NAS doesn't have a gigabit port.
I can connect to the HP microserver with any protocol, I think I will use SSH, but to the old NAS I can only connect with SMB or FTP… I'm not particularly thrilled, but I will adjust.
I start connecting to the server:
joe@joe-toshiba:$ ssh -t email@example.com The authenticity of host 'server_addr (192.168.5.10)' can't be established. ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.5.10' (ECDSA) to the list of known hosts. root@server_addr's password: Linux nas 5.19.0-0.deb11.2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.11-1~bpo11+1 (2022-10-03) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sun Nov 27 02:46:35 2022 from 192.168.5.201 root@nas:~#
From here I'll have to go to a directory inside one of the disks containing the data. OMV mounts the disks in a directory called
/srv/. I have already installed and configured
mergerfs, a program that allows two discs with two different contents of “join” in a single resource. Maybe we will talk about it in another article.
root@nas:~# cd /srv/mergerfs/Public/nas/
At this point I already know I want to copy the directory “Public” from the old NAS and all its contents. I'll have to run an FTP command that connects me and starts copying all data in the background. I don't want to have to keep the laptop on for the duration of the operation just so as not to interrupt the launched process.
The simplest command I can run is evergreen
# wget -rb ftp://joe:My5ecreTp4ssword@192.168.5.2/Public/
-r allows you to resume the download of a large truncated file (even accidentally) where the download stopped from. While with
-b I put the process in the background.
In this way, however, my password would remain unencrypted in the history of the terminal (if you decide not to clear your history). And it would also remain unencrypted among the server processes (
# ps ax | grep wget 271089 ? Rs 26:44 wget -rb ftp://joe:My5ecreTp4ssword@192.168.5.2/Public/ 274190 pts/2 S+ 0:00 grep wget
I could perhaps create a one line script that summarizes the command… but maybe it's easier to create the file
.wgetrc that contains the credentials.
## Credentials for the good ol' NAS @ 192.168.5.2 user=joe password=My5ecreTp4ssword
Once the file has been saved in the user's home, I will be able to launch the download via FTP without indicating the credentials.
# wget -rb ftp://192.168.5.2/Public/
If I realize I've made a mistake and want to stop the command that's now in the background I always can “guys” the old fashioned way. As we have seen before “
ps ax | grep wget” shows the process and its PID, while “
kill PID_ID” it will kill the process (substitute
PID_ID with the real PID to kill).