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:
Target | Command | Description |
---|---|---|
remote | ls | List files in remote device path |
local | lls | List files in local device path |
remote | cd | Change directory in remote device path |
local | lcd | Change directory in local device path |
local -> remote | put <local_file> | Send file from local to remote device |
local <- remote | get <remote_file> | Receive file from remote device to local device |
local | exit | Exit 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
- 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
-
We execute
ls
to list files in remote device path.sftp> ls
We will see the following output.
R_Documents
-
We execute
cd
to change directory in remote device pathsftp> 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
-
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)
-
We execute
lls
to list files in local device path.sftp> lls
We will see the following output.
Documents Downloads R.txt
-
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)
-
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
-
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
-
Execute
exit
to exit from remote device.sftp> exit