sftp 工具的使用

这个工具可以使用跟 ssh 协议进行文件传输,在一些情况下还是挺好用的
用连接远程计算机

1
sftp root@192.168.1.1

登录成功后用 help 可以看到 sftp 的基本指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-Ppr] remote [local] Download file
reget remote [local] Resume download file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-Ppr] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help

简单的做个总结,在可以直接使用 lls cd pwd 这些命令进行路径操作
要对本地的命令进行操作的话,需要在这些基础命令的前面加上一个字母 “l”
也就是 cd 变成了 lcd,pwd 变成了 lpwd,ls 变成了 lls
若要从对方机器上下载文件到本地的话,使用 get 命令

1
get /etc/hosts

这样就下载到了本地的当前目录下了
若要从本地上传文件到对方机器,可以使用 put 命令

1
put /etc/hosts

若要上传或者下载整个目录,则加上 - r 参数即可

1
2
get -r ./hello
put -r ./12345

操作完之后退出也有好几个命令

1
2
3
exit
quit
bye

这个工具在进行文件传输的时候还是很方便的,能够进行交互式的文件管理操作,但是有一些系统比如 OpenWRT 之类的话,可能会默认没安装 sftp-server,这个时候也就只能用 scp 了。