Let’s explore different ways to transfer the files between PC and Raspberry Pi with examples.
1) Using scp
– If ssh/scp is enabled on Raspberry Pi. Ping Pi board IP and see if it is reachable.
ping <pi-ip>
ex: ping 192.168.1.5
– Copy from PC to Raspberry Pi
- Open the terminal on the PC and run the below command
scp <file-name on PC> pi@<raspberry-pi-ip>:<directory where you want to copy on pi>
The password is "raspberry"
ex: scp file.txt pi@192.168.1.6:/home/pi/driver/
– Copy from Raspberry Pi to PC
- Open the terminal on the PC and run the below command
scp pi@192.168.1.6:< file-name on raspberry-pi with full path> <directory where you want to copy on PC>
The password is "raspberry"
ex: scp pi@192.168.1.6:/home/pi/driver/file.txt /home/user/ek/doc/
– Copy a directory from PC to Pi and vice-versa
- Use scp command with ‘-r’ option to transfer the directory.
scp -r <directory on PC> pi@<raspberry-pi-ip>:<directory where you want to copy on pi>
scp -r file/ pi@192.168.1.6:/home/pi/driver/
scp -r pi@192.168.1.6:< directory-name on raspberry-pi with full path> <directory where you want to copy on PC>
scp -r pi@192.168.1.6:/home/pi/driver/file/ /home/user/ek/doc/
2) Using GUI
– If vnc interface is enabled on Raspberry Pi.
– Download any VNC viewer application on the PC. In the below example, Realvnc viewer is shown. Download from here.
– Enter Raspberry Pi IP in the GUI and press enter.
– enter username: pi, enter password: raspberry
– There is an option for file transfer. Use it and transfer a file from PC to Pi and Vice-versa.
– In the above example, RealVNC is used. You can use any VNC viewer and give it a try.
– Some VNC also supports simple copy-paste shortcuts to transfer files between remote target(Raspberry Pi) and PC.
3) Using USB
– Insert USB Pen driver in PC. Inserted in ubuntu system in this example. You can use Windows or Mac OS also. The drive name is ek here.
– Copy file from PC to USB pen drive.
– Insert USB to the Raspberry PI.
– Go to the directory /media/pi/<usb_name>.
- <usb_name> is the same which is shown in the PC when USB is inserted. <usb_name> is ek in our case.
– use cp command to copy from USB to the Raspberry Pi board or vice-versa.
– copy from USB to Pi
- cp /media/pi/<usb_name> <directory of Pi where you want to copy>
- Use sudo cp if permission is denied as shown below image.
– copy from Pi to USB
- cp <file of Pi which you want to copy> /media/pi/<usb_name>
- Use sudo cp if permission is denied as shown in the below image.
– In the below example image, led.c is copied from Pi to USB. Same way you can copy from USB to Pi as well.
– Now again insert a USB Pen drive into the PC. Copied file(led.c) in the USB can be seen.
4) Using FTP/SFTP
– FTP is the file transfer protocol. click here to get FTP manual page or run “man ftp” command in the terminal.
– SFTP is the secure file transfer protocol. click here to get the SFTP manual page or run “man sftp” command in the terminal.
– There are many FTP/SFTP tools available. Download any FTP/SFTP tools.
– Filezilla open-source software is used in our example.
– Download FileZilla for Mac OS, Windows, or Linux from the Filezilla official website.
– Open Filezilla, and Enter the hostname as Pi IP(192.168.1.5 in this example).
– Username: pi, Password: raspberry, Port: 22 for sftp, 21 for FTP.
– There will be two windows shown. Drag and drop files that need to be transferred.
– There are also ways to transfer files using the FTP command line.
– Need to configure FTP in PC and Pi then use FTP commands.
Note: This article covers a couple of ways to transfer files from Raspberry PI to PC and vice-versa. If you have any additional ideas then please mail us at info@embeddedkernel.com. Your idea will be listed here. TIA.