Copying Files to the Raspberry Pi Over a Network
This article will be dealing with transferring files to and from the Pi over a network. As an example, some web site files will be transferred to the Pi for an Apache server on the Pi. An article, has already been written showing how to install the server on Debian, but Arch Apache instillation instructions are shown below because this article series now uses Arch Arm.
Apache
Apache can be installed via pacman.
$
sudo pacman -S apache
resolving dependencies...
looking for conflicting packages...
Packages (3) apr-1.7.0-3 apr-util-1.6.1-9 apache-2.4.54-2
Total Download Size: 1.82 MiB
Total Installed Size: 7.16 MiB
Then, it needs to be enabled and started with systemctl.
$
sudo systemctl start httpd
$
sudo systemctl enable httpd
Files to be served by http are stored in /srv/http
. By default, root privilege is needed to modify anything in that directory. To modify it more easily (and because this is a test server for which security is not really a concern), I changed the directory's group to wheel
, and gave the group read, write, and execute privilege.
$
sudo chgrp wheel /srv/http/
$
sudo chmod g=rwx /srv/http/
scp
scp
is a part of OpenSSH and can securely Transfer files and/or directories over a network through SSH. It is very similar to the cp
command.
When sending a file to the Pi, first the file that is to be sent is listed. Then the destination is given. The destination is formatted as follows: username, @, IP address:, destination path.
$
scp file user@000.000.0.00:/destination/file/path
When sending a file from the Pi, the same is done in reverse.
$
scp user@000.000.0.00:file destination
However, one should remember that, in order to send files from the Pi back to the controlling computer, the OpenSSH daemon must be enabled on the controlling computer. The commands needed to turn the daemon on and off are shown below.
$
sudo systemctl start sshd
$
sudo systemctl stop sshd
As an example, I will more the files from a webs site that I made a few years ago to the server. Notice that the -r
flag is used because directories need to be moved.
$
scp -r ./* alarm@192.168.1.29:/srv/http/
rsync
rsync
can perform basically all of the functions that scp
can perform but also has some additional features. Perhaps most importantly, it can selectively copy only files that have more recent modification dates than files with the same name in the destination directory. For instance, if a large web site is stored both on a local computer and on the Pi, local changes can be moved to the Pi without recopying all of the unchanged files.
The -r
flag copies files recursively, the -v
flag gives a verbose output, and the -u
flag only updates files that need to be updated.
$
rsync -vur file user@000.000.0.00:destination
$
rsync -vur user@000.000.0.00:file destination
Previous | Published November 2, 2022 | Next |
---|