Transferring files with SCP between raspberries

I was playing with Raspberry Pi Model B for quite a long time. I tweaked few settings, and wrote couple helper scripts. After some time second Raspberry Pi 2 arrived. I realized that most settings and scripts that were working on previous should do fine on a new one. I needed to copy few files from one Raspberry to another. For this purpose, I decided to use Secure Copy (SCP). This is a file-sending command over SSH.

raspbery pi

Raspbian OS already come with SCP installed, so you can use it right away. (it is missing you can install it by running the command sudo apt-get install scp).

With SCP, you can send files in both directions – from local to remote and copy from remote location to local space. Let’s get to some practical examples how I downloaded my scripts to new Raspberry pi from another board. My scripts are located in folder /home/pi/myscripts.

The simplest way is to copy a single file. To make things easy to track, connect to both raspberry pi boards via ssh (I use PuTTY). On a destination computer, navigate to the folder where you want to copy the file and run the command:

scp pi@192.168.0.104:/home/pi/myscripts/images1s.sh .

scp_single_file

pi@192.168.0.104 – is a username and IP of remote computer. Then follows semicolon and remote file location. .(dot) at the end is current location on local machine where file has to be copied. When you enter ther command you will be prompted for remote computer password.

If you have lots of files to transfer then use recursive option to copy entire folder like this:

scp –r pi@192.168.0.104:/home/pi/myscripts .

Here you can see you need to enter source folder which is recursively copied to your local place.

Also you can send files to another raspberry pi. For instance:

scp my.db pi@192.168.0.100:/tmp

This will send my.db file from current folder to remote machine /tmp folder.

There are more handy options to be used with SCP command. For instance “-p” option preserves original access and modification times. If you are transferring large files or groups, you can use compression option “-C”.

More options and information you can find by typing man SCP in ssh.

Leave a Reply