Transfert de fichiers en SSH.

Transfer files to the Raspberry Pi without FTP with SSH.

Updated the 27 August 2020 - 0 Comments - , , , ,

ⓘ This article may have been partially or fully translated using automatic tools. We apologize for any errors this may cause.

I'm sure you've needed to transfer files from your PC to your Raspberry Pi over the network before. If so, chances are you had to install an FTP server. And yet there was a much easier way …

In this tutorial we will see how to transfer files from our computer to our Raspberry Pi without having to install an FTP server, but only by using the SSH server already installed on the Raspberry Pi and the command scp !

The material used in this tutorial

In this tutorial we will use the following material:

In addition, to complete this tutorial you will also need to have enabled the SSH server of your Raspberry Pi. If you don't know how, check out our tutorial to enable SSH.

What is SCP transferring files using SSH?

If you're using the Raspberry Pi you've probably heard of SSH, a tool that lets you take control of a computer remotely from the command lines. But what you might not know is that SSH isn't just for that.

One of the many possible uses for SSH is SCP, for Secure CoPy. This is a protocol for transferring files from one computer to another, relying on the SSH protocol which will encrypt the transferred data.

Take control of your Raspberry Pi with SSH
SSH is a remote control protocol with data encryption.

For us who work with the Raspberry Pi, SCP is therefore particularly interesting, since the Raspberry Pi already has an integrated SSH server and therefore we will not have to install or configure a server, as is the case with FTP.

If you're new to SSH at all, you might want to read our SSH tutorial before continuing. It's not essential, but I think it makes things clearer.

Transfer files with SCP from a Linux computer

If you are working from a Linux computer, nothing is easier than sending a file using SCP, just use the command scp from your terminal.

The command scp is used as follows: scp <ressource_a_envoyer> <destination>

First, you put the resource to send (there can be several, separated by spaces) and at the end of the command where to send them.

Resources and destinations are in fact identified by paths. They can be simple file paths, or they can be login credentials associated with file paths.

Transfer of a file to SCP.
Here for example, you can see the transfer of a save file to the Pi's temporary directory.

And it works like SSH, you fill in a user account, a host, a path, you are asked for the account password, and if the password is correct the file is transferred.

Some examples to better understand SCP paths.

To help you better understand how it works, here are some examples of SCP paths and commands.

In all the examples below, we will send and retrieve files from a Raspberry Pi connected over the network to the IP address 192.168.0.15 and with the default user, pi.

Send file /home/bernard/photo.jpg from your PC to the directory /home/pi of the Raspberry:

scp /home/bernard/photo.jpg pi@192.168.0.15:/home/pi

 

Recover File /home/pi/toto.txt on the Raspberry Pi and copy it to the folder /tmp from your PC:

scp pi@192.168.0.15:/home/pi/toto.txt /tmp

 

Transfer files ~/file1 and ~/file2 from your PC to the folder /home/pi from your Raspberry:

scp ~/file1 ~/file2 pi@192.168.0.15:/home/pi

 

Finally, in a special case, transfer the entire file /home/pi from your Raspberry Pi to a new folder ~/tmp_pi in your PC:

scp -r pi@192.168.0.15:/home/pi ~/tmp_pi

Note the use of the argument -r which allows file transfer.

 

Under Linux, therefore, nothing could be easier than to transfer a file to or from your Raspberry Pi with SCP via the network!

Transfer files to the Raspberry Pi from Windows or Mac OS

On Windows or Mac OS, as is often the case, we're not going to transfer the files directly to the command lines, but we'll be using a GUI instead.

We're actually going to be using a tool that you probably know if you've used an FTP server before, FileZilla. Indeed, if FileZilla is originally an FTP client, it also acts as an SFTP and SCP client.

Go to the FileZilla download page, take the version suitable for your system, install there and launch the software.

FileZilla home interface
When FileZilla starts, only the left part (your computer) is available.

Once FileZilla is launched, click on "File", "Site manager", a window will open allowing you to manage your sites. Do "New Site", the right part allows you to enter the connection information to your Raspberry Pi.

In the "Host" section, enter the IP address of your Raspberry Pi (if you do not know it, go to our tutorial to find the IP address of your Raspberry Pi).

In the port part, enter the SSH port of your Raspberry Pi, by default it is 22.

Most importantly, in the "Protocol" section select SSH File Transfer Protocol, it is an SSH-based transfer protocol that replaced SCP and is supported by FileZilla.

Finally, for the "Authentication type" part, choose "Normal", and enter your Raspberry user, pi and your password.

All you have to do is click on "Connection".

Interface for adding a site for SCP / SFTP transfer.
Your fields should look pretty much like this, adjusting the IP of course.

You should then see a message appear asking you to validate the host server key. This is because unlike FTP, SFTP uses SSH to encrypt data, and therefore needs an encryption key. Click on "Validate".

ssh key confirmation message
You must validate the server encryption key.

And there you are, you are connected to your Raspberry Pi! You can now explore the filesystem just like your Pi user might.

FileZilla interface with SFTP connection to the server.
Now that you are connected to the server, you can see its files on the right side.

This means that you have the right to do anything on the server that your Pi user can do. You can easily transfer files between your Raspberry Pi and your Computer by simply dragging and dropping!

Now it's your turn !

Share
Newsletter
Author:
Raspberry Pi FR
Join the Raspberry Pi community
A $35 computer already sold 10 million copies
BUY THE NEW RASPBERRY PI 4
Related tutorials
Create a Wi-Fi hotspot in less than 10 minutes with Pi Raspberry! Install Android on his Raspberry Pi How to install a web server on the Raspberry Pi (Apache + PHP + MySQL) Create a NAS with your Raspberry Pi and Samba Install WordPress on a Raspberry Pi (with Nginx).
No Comments
Share
Newsletter Sign-Up
Subscribe to the newsletter.
¿Te gustó este artículo?
¡Suscríbete y mantente informado!