Smart Cities - Transferring Files using Secure Copy

From Sensors in Schools
Jump to navigation Jump to search

Introduction

  • The fastest way to copy files between two computers is to use Secure Copy (scp)[1].
  • This method is executed from the Terminal and hence eliminates the overhead of a GUI application.
  • It is both fast and secure.
  • Files can be transferred in both directions.

Prerequisites

  • In this lesson it is assumed that Secure Shell (SSH) has been enabled on both computers.

Enabling SSH on a Raspberry Pi

  • In the Terminal enter the command sudo raspi-config

  • In the raspi-config menu select Interface Options

  • Select SSH (Secure Shell) and then select Enable SSH

  • SSH will now be enabled. There is no need to reboot the computer.
  • Exit raspi-config

Copy File From Local Host to Remote Server

  • In this example we will copy a file from a local host computer to a remote computer on the same network [2].
    • 192.168.1.105 Local computer IP address
    • 192.168.1.120 Remote computer IP address
    • On the Host computer create a new directory named test with the command mkdir test
    • Enter the directory using cd and create an empty file named file_to_send.txt with the command touch file_to_send.txt
  • To send the file enter the command scp file_to_send.txt pi@192.168.1.120:/home/pi/
  • You will be asked to enter the pi user password on the Remote computer

  • The file will now appear on the Remote computer in the /home/pi directory

Copy Files From Remote to Local

  • In this example we will copy a file from a remote computer to a local computer (the one issuing the commands) on the same network.
    • 192.168.1.105 Local computer IP address
    • 192.168.1.120 Remote computer IP address
    • A file named remote_file.txt has been created on the remote computer.
  • To send the file from the remote computer to the local computer (user home directory) enter the command scp pi@192.168.1.120:/home/pi/remote_file.txt .
  • The dot (.) at the end means to copy to file to the user home directory of the local computer.
  • You will be asked to enter the password of the pi user on the Remote computer.

Copy Files From Remote to Local using Public and Private keys

  • Secure Copy (scp) works the same way but with a few Options added to the instruction.
    • -P the Port may need to be specified
    • -i