Low Orbit Flux Logo 2 F

How To Transfer Files to Raspberry Pi

If you are working with a Raspberry Pi and you are accessing it remotely, chances are you will need to transfer files to that Raspberry Pi. This is going to come up at some point. Here are some quick answers. If you need more info or want to try other methods, keep reading past the quick answer.

Quick Answer:

From OSX, Linux, BSD:


scp my-file.txt  pi@my-raspberry-pi-server:/home/pi

Download WinSCP HERE and just fill in the parameters.

More Options / Details

Here are a few different methods you could use to transfer files to a Raspberry Pi. We’re going to cover them all:

We’re assuming that you are running Linux on your Raspberry Pi and either Linux, Windows, or OSX on your client system. The top two tool choices are SCP and Samba. If you just want to transfer some files over or if you want to automate that transfer, SCP is a good choice. If you want to mount a directory as though it were a drive on your local system then Samba is a great choice. SFTP and SSHFS are also OK choices that might be good options depending on how you like to work.

How you actually connect to your Raspberry Pi will depend on what OS you are connecting from and what tools you prefer to use. We’re going to show you how to connect from any of these systems:

Using SCP - How To Transfer Files to Raspberry Pi

This method allows you to specify a source and destination as parameters in a command. You don’t actually mount or browse the remote filesystem. This is usually done from the command line on Linux and OSX. For windows people typically use GUI tools like WinSCP. You can also apparently use SCP with PowerShell.

From OSX, Linux, BSD you can copy a single file to a directory like this:


scp my-file.txt  pi@my-raspberry-pi-server:/home/pi

You can copy a directory using the “-r” flag like this:


scp -r my-dir  pi@my-raspberry-pi-server:/home/pi

—screenshot here—

From Windows you will generally use a tool WinSCP. This gives you a nice drag and drop interface. Download WinSCP HERE and just fill in the parameters.

—screenshot here—

Another tool for Windows that you will often see people recommend is called FileZilla. I would NOT recommend it. It has a history of being packaged together with malware. You might be able to get clean versions of it today but I still wouldn’t trust it.

Using Samba - How To Transfer Files to Raspberry Pi

This is an excellent method if you want an actual share that you can mount and browse. It is also a good option if multiple people might need to access the same files. This does take a tiny bit of effort to get setup but it isn’t a big deal.

Step one would be to set up Samba on your Raspberry Pi.


sudo apt-get update
sudo apt-get install samba samba-common-bin

Edit your Samba config file:


sudo nano /etc/samba/smb.conf

It should look somewhat like this:


[global]
netbios name = Pi
server string = The Pi File Center
workgroup = WORKGROUP

[MYHOME]
path = /home/pi
comment = a home directory
writeable=Yes
create mask=0777
directory mask=0777
public=no

Set a Samba Password:


sudo smbpasswd -a pi

Restart Samba:


sudo service smbd restart

Client Access

Windows

From Windows you can access the share through File Explorer:

Linux

From Linux you can mount your share. Make sure you have the client tools installed. This command should work on Ubuntu:


sudo apt-get install cifs-utils

Mount the share like this:


sudo mount -t cifs -o vers=1.0,user=pi,pass=xxxxxxxxx \
//RASPBERRYPI/MYHOME /mnt

OSX

On OSX you can mount a Samba share.

SFTP - How To Transfer Files to Raspberry Pi

This stands for Secure File Transfer Protocol or SSH File Transfer Protocol. It is basically like using FTP over an SSH connection. It allows you to navigate the remote system and transfer files.

Linux / OSX

From Linux or OSX you can use the following command to establish a connection:


sftp pi@my-raspberry-pi

Here are some SFTP commands to get you started:

help get help
pwd show current dir ( remote )
ls show files ( remote )
cd my-dir change dir ( remote )
lpwd show current dir ( local )
lls list files ( local )
lcd my-dir change dir ( local )
get remoteFile localFile download a file
get -r someDirectory download a directory
get -Pr someDirectory download a directory and preserve permissions
put localFile upload file
put -r localDirectory download a directory
df -h show disk usage

Windows

For Windows you will probably just want to use WinSCP the same way that you would with SCP. Download WinSCP HERE and just fill in the parameters.

SSHFS - How To Transfer Files to Raspberry Pi

Another neat tool you can use to transfer files is SSHFS. This basically allows you to mount a remote directory directly over ssh. The syntax is really simple on Linux. It is easier and more flexible than scp and sftp.

Linux

You might need to install this first on older versions of Ubuntu. I didn’t need to install it on Ubuntu 19.04. You can install like this if needed but see if it is installed already first.


sudo apt-get install sshfs

You can mount a remote dir over ssh like this:


sshfs pi@my-raspberry-pi:/home/pi  

Unmount it like this:


umount -u /home/user1/pi

Windows and OSX

You can use this on Windows and OSX too. OSX looks a bit more involved. You can find instructions on getting it setup HERE. Using WinSCP should allow you to do this from Windows (the same tool we looked at for scp and sftp).

FTP - How To Transfer Files to Raspberry Pi

Don’t use FTP. You can but there is really no reason to do this. It has been obsolete since before the first Raspberry Pi had ever been created. It is an insecure protocol that doesn’t encrypt your data. That may not matter on a local network but there is still no reason to set this up and use it when more secure options are easier to use.

References

Some SFTP Documentation