Sometimes, when we are testing our devices, we need to send files from our Linux based laptop to our Raspberry PLC so that we can execute them.
On other occasions, we have to do the opposite and send either files or directories from our Raspberry PLC to our laptop.
Now, you won't be to worry anymore about sending files through email, or pendrive or any other way that makes you loose time.
According to Wikipedia, the Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Typical applications include remote command-line, login, and remote command execution, but any network service can be secured with SSH.
SSH provides a secure channel over an unsecured network by using a client–server architecture, connecting an SSH client application with an SSH server. The protocol specification distinguishes between two major versions, referred to as SSH-1 and SSH-2. The standard TCP port for SSH is 22. SSH is generally used to access Unix-like operating systems, but it can also be used on Microsoft Windows. Windows 10 uses OpenSSH as its default SSH client and SSH server.
SCP stands for secure copy, which is a command-line utility that allows you to securely copy files and directories between two remote locations, from local to remote system and from remote to local system.
If you type the command below, you will see the following information:
Scp copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh. scp will ask for passwords or passphrases if they are needed for authentication.
The source and target may be specified as a local pathname, a remote host with optional path in the form [user@]host:[path], or a URI in the form scp://[user@]host[:port][/path]. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:’ as host specifiers.
When copying between two remote hosts, if the URI format is used, a port may only be specified on the target if the -3 option is used.
First of all, check that your SSH is activated:
sudo systemctl status ssh.service
If it is not, start it:
sudo systemctl start ssh.service
Then, we must have clear that the structure is always the same, with optional options after scp:
Assuming the following information about Raspberry PLC:
- User: pi
- Eth IP Address: 10.10.10.20
- Wlan IP Address: 192.168.1.2
Let's see some examples!
Copy From Remote to Local Host
scp email@example.com:/home/pi/sample-file-from-raspberry.txt /home/user/file-in-linux-laptop.txt
scp firstname.lastname@example.org:/home/pi/sample-file-from-raspberry.txt /home/user/file-in-linux-laptop.txt
Copy From Local to Remote Host
scp -r /home/user/test-directory email@example.com:/home/pi/
scp scp -r /home/user/test-directory firstname.lastname@example.org:/home/pi/
Checkout the manual for more options and information about scp