You’ve had success with your latest Raspberry Pi project. Perhaps you’re using it to create photos, music, or even video? Whatever the case, at some point you’re going to want an easy way to get the data off the Pi’s SD card and onto your PC’s HDD.
This can be tricky.
With virtually no support from cloud services, the answer comes in the form of removable media, email, and local network tricks. If you’ve ever had to copy data to or from a Raspberry Pi and run into problems, these five methods should help you out in future.
1. Send Data via Email
This is probably the most obvious option — it’s certainly the first thing I tried. By accessing the Raspberry Pi’s default email client (Claws Mail as of the PIXEL desktop version of Raspbian Jessie), it’s a simple task to setup your email account, add an attachment, and send the data.
You might prefer to access Gmail via the Chromium web browser — either option is fine.
How you send the email is up to you. If you’re using Gmail, you’ll be able to save the message as a draft. Then when you sign into Gmail on your main PC, it will be there. Otherwise, if you’re using an email client, just email it to your own address, or a second email account you have access to.
If you don’t have a second email account but have a Facebook account, then you have a Facebook email account. In a squeeze, send the data to this.
2. Access Cloud Storage in the Browser
Another obvious-but-slow option is to access one of your cloud accounts and sync data this way. Unfortunately, no well-known cloud services offer apps for the Raspberry Pi, so your best bet is to upload your files via the Chromium browser.
But which service should you use?
Dropbox and Box are both available via the browser, but are slow. OneDrive and Google Drive, meanwhile, can barely be used. We’d suggest sticking to whichever you find the most useful.
3. Use a USB Drive
Another sensible choice is to use a USB drive. Simply insert a formatted drive into a spare USB slot in your Raspberry Pi, and wait for it to appear in the Raspbian file manager. If you’re using an older Pi or a Raspberry Pi Zero and are short of USB ports, then it’s time to employ a USB hub. While a standard USB hub will be fine for a USB flash device, note that a powered hub will be needed for devices that will draw power from the Pi.
With the USB drive inserted, it should automatically mount. If not, you’ll need to mount it manually. Begin by finding its unique ID:
ls -l /dev/disk/by-uuid/
Typically you’ll find an entry called sda1 (although this may differ), so keep a note of the name before proceeding.
Next, create a mount point. This is essentially a directory that will display the contents of the drive.
sudo mkdir /media/usb
(You don’t have to call it “usb” but it helps.)
Next, ensure the Pi user owns the folder. Otherwise, you won’t be able to view the contents!
sudo chown -R pi:pi /media/usb
You can then mount the drive with:
sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi
Once you’re done, you can easily copy files to the USB drive and, after safely ejecting, copy them to your main computer. To manually unmount use:
sudo umount /media/usb
4. Send and Receive Data With SCP
A little complicated to get working, the idea with this is that you can use the command line to send and receive data between your Raspberry Pi and your PC.
A command called scp (Secure Copy Protocol) makes this possible. To use it, you’ll first need to establish an SSH connection to your Raspberry Pi. This works best for Linux, as Windows users will need to install an SSH client to make it work. Once connected, in Linux, type:
This uses the scp command, identifies the device and the default username, and specifies the name of the file. The file.txt document will be transferred from the Pi to your computer’s Home directory.
To copy file.txt to your Pi, use:
scp file.txt email@example.com:
(That : at the end is very important!)
Again, the home directory is the destination. To change this, specify a different directory, such as:
scp file.txt firstname.lastname@example.org:subdirectory/
This method is similar to the ADB push command used to send data to and from an Android device when flashing a new ROM or rooting.
5. The Best Option: SFTP
If you have a good FTP client that has support for the secure SFTP, then this is perhaps the best option to grab data from your Raspberry Pi. For this, the flexible, open source FileZilla project is a good place to start. You can download a copy from filezilla-project.org.
SFTP stands for SSH File Transfer Protocol, so as long as SSH is enabled on your Raspberry Pi (typically via the raspi-config screen) you can use SFTP for pushing and pulling files in the GUI.
With FileZilla running, open File > Site Manager, and click New Site. From here, enter the IP address of your Raspberry Pi in the Host box (or just raspberrypi.local if you have Bonjour services running).
Continue filling the form, selecting SFTP – SSH File Transfer Protocol for the Protocol and Normal for the Login Type. Enter the current Raspbian username and password for User and Password (by default this is pi and raspberry). You might want to click Rename to give the connection a descriptive name — this is particularly useful if you use FileZilla regularly.
As long as the Pi is already booted, you can click Connect to begin the connection. In FileZilla, the local device (your PC) is represented on the left, with the remote computer (your Raspberry Pi) on the right. You’ll need to browse through the directories on both sides to find the source and destination files. Once you’ve done this, you can copy files from your Raspberry Pi by dragging them to the left pane, or right-clicking and selecting Download.
(To copy files to the Pi, simply move them from left to right.)
Although a little fiddly to setup, we reckon SFTP is the best solution for transferring files to and from your Raspberry Pi. For small files like MP3s and images, you can also use the boot partition to copy data.
And if you’re interested in using your Raspberry Pi as a desktop PC, check out what we’ve learned from doing that.