top of page
WFU Robotics

Copying Files Between a Computer and a Pi

Updated: Apr 10, 2021

Copying files between a Raspberry Pi and your local computer is a great thing to do often. If you like coding in your own Python editor on your laptop, if you don't have an external monitor, or if you just want to save a backup of your scripts, this is something you should learn how to do. It's also extremely easy.


We will be using the "scp" command, which takes as arguments the address of the Pi, the path to the file to copy, and path to the directory the file should be copied into.


We will demonstrate how to do this from either the command line (Windows) or the Terminal (Mac OS/Linux) application on your local computer.


Suppose we want to copy a python file, diddy2FollowBall.py, from the folder at /home/pi/diddyborgv2/diddy2FollowBall.py, to a folder on our local computer, /Users/csuser/Documents/.


These file paths are full file paths, in that they start at the root directory, "/". If you want to find out the correct file path of a folder on the Pi, navigate to that folder in Linux (on the Pi), and then type "pwd".


Once you have the correct file paths, you can proceed. Make sure the Pi is turned on throughout this whole process.


Continuing with our example, in Terminal on a local Mac/Linux system , we would enter:

scp <username>@<ip_address>:/home/pi/diddyborgv2/diddy2FollowBall.py /Users/csuser/Documents/

Some things to note: there is a space between scp and <username>. Also, enter the username of the Pi (default is pi) in place of "username", and do not enter the <>, as those are just placeholders. Same thing applies for <ip_address>.


In addition, there must be a colon, ":", between the ip address and the file path of the file to copy from the Pi. There also must be a space between that file path and the file path of the directory to copy to (in this case between .py and /Users/). The overall structure of the scp command is:

scp <username>@<ip_address>:<file_to_copy> <directory_to_copy_to>

This structure is largely the same on Windows, except file paths are specified differently on Windows OS. In our example, this might be:

scp <username>@<ip_address>:/home/pi/diddyborgv2/diddy2FollowBall.py C:\Documents\

Alongside a different file path, scp also requires we use a "\" for Windows file paths, versus a "/" for Linux-based systems.


If we want to copy a file from our local computer to the Raspberry Pi, the only change is the order of the arguments. A sample template might be:

scp <file_to_copy(local)> <username>@<ip_address>:<directory_to_copy_to(on Pi)>

8 views0 comments

Recent Posts

See All

Comments


bottom of page