SFTP

SSH File Transfer Protocol (also known as Secure File Transfer Protocol or SFTP) is a network protocol that provides file access, file transfer, and file management over any reliable data stream. -- wiki

[[TOC]]

Usage

Connection

Connect to remote device by HostName/IP with UserName (ex. <host_name>@)

sftp 192.1.1.1@richardyim # sftp <host_name>@<username>

The prompt will change to sftp>. The following are the available commands.

Commands:

TargetCommandDescription
remotelsList files in remote device path
localllsList files in local device path
remotecdChange directory in remote device path
locallcdChange directory in local device path
local -> remoteput <local_file>Send file from local to remote device
local <- remoteget <remote_file>Receive file from remote device to local device
localexitExit from remote device

Guide

Local Device:

|_ Documents
  |_ A.txt
  |_ B_directroy
    |_ B_1.txt
    |_ B_2.txt
  |_ C.txt
|_ Downloads

Remote Device:

|_ R_Documents
  |_ R.txt
  |_ R_B_directroy
    |_ R_B_1.txt
    |_ R_B_2.txt
  |_ R_C.txt
  1. We execute sftp from local device to connect to remote device in path home directory (*: indicates the current path).
*  -----[ sftp <host_name>@<username> ]  -----> *
*_ Documents                                    *_ R_Documents
* |_ A.txt                                         |_ R.txt
* |_ B_directroy                                   |_ R_B_directroy
* | |_ B_1.txt                                     |  |_ R_B_1.txt
* | |_ B_2.txt                                     |  |_ R_B_2.txt
* |_ C.txt                                         |_ R_C.txt
*_ Downloads
  1. We execute ls to list files in remote device path.

    sftp> ls
    

    We will see the following output.

    R_Documents
    
  2. We execute cd to change directory in remote device path

    sftp> cd R_Documents
    sftp> ls
    

    We will see the following output. Which is contents inside the R_Documents directory.

    R.txt R_B_directroy  R_C.txt
    
  3. We execute get to receive file from remote device to local device.

    sftp> get R.txt
    

    We will see the following output. The R.txt file is copied to local device.

      <-----[ get R.txt ]  -----
    *_ Documents                 |_ R_Documents
    * |_ A.txt                    |  *_ R.txt
    * |_ B_directroy              |  *_ R_B_directroy
    * | |_ B_1.txt                |  *  |_ R_B_1.txt
    * | |_ B_2.txt                |  *  |_ R_B_2.txt
    * |_ C.txt                    |  *_ R_C.txt
    *_ Downloads
    *_ R.txt (copied)
    
  4. We execute lls to list files in local device path.

    sftp> lls
    

    We will see the following output.

    Documents Downloads R.txt
    
  5. We excute lcd to change directory in local device path.

    sftp> lcd Documents
    sftp> lls
    

    We will see the following output. Which is contents inside the Documents directory.

    A.txt B_directroy C.txt
    

    Status of the files in local device.

    |_ Documents            |_ R_Documents
    | *_ A.txt                |  *_ R.txt
    | *_ B_directroy          |  *_ R_B_directroy
    | * |_ B_1.txt            |  *  |_ R_B_1.txt
    | * |_ B_2.txt            |  *  |_ R_B_2.txt
    | *_ C.txt                |  *_ R_C.txt
    |_ Downloads
    |_ R.txt (copied)
    
  6. We execute put to send file from local device to remote device.

    sftp> put C.txt
    

    We will see the following output. The C.txt file is copied to remote device.

       -----[ put C.txt ]  ----->
    |_ Documents                  |_ R_Documents
    | *_ A.txt                    |  *_ R.txt
    | *_ B_directroy              |  *_ R_B_directroy
    | * |_ B_1.txt                |  *  |_ R_B_1.txt
    | * |_ B_2.txt                |  *  |_ R_B_2.txt
    | *_ C.txt                    |  *_ R_C.txt
    |_ Downloads                  |  *_ C.txt (cpoied)
    |_ R.txt
    
  7. We execute ls to list files in remote device path.

    sftp> ls
    

    We will see the following output. Which is C.txt inside the R_Documents directory.

    R.txt R_B_directroy  R_C.txt C.txt
    
  8. Execute exit to exit from remote device.

    sftp> exit