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
sftpfrom 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
lsto list files in remote device path.sftp> lsWe will see the following output.
R_Documents -
We execute
cdto change directory in remote device pathsftp> cd R_Documents sftp> lsWe will see the following output. Which is contents inside the R_Documents directory.
R.txt R_B_directroy R_C.txt -
We execute
getto receive file from remote device to local device.sftp> get R.txtWe 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
llsto list files in local device path.sftp> llsWe will see the following output.
Documents Downloads R.txt -
We excute
lcdto change directory in local device path.sftp> lcd Documents sftp> llsWe will see the following output. Which is contents inside the Documents directory.
A.txt B_directroy C.txtStatus 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
putto send file from local device to remote device.sftp> put C.txtWe 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
lsto list files in remote device path.sftp> lsWe 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
exitto exit from remote device.sftp> exit