使用sftp远程传输文件
如果想要在上传文件到SSH服务器或从中下载文件时使用交互工具,可以使用sftp工具。 sftp的会话与典型的FTP会话相似,但使用SSH服务器的安全身份验证机制和加密数据传输功能
命令:sftp [user@]remote_host
注:sftp会话接受各种命令,这些命令在远程系统上运行的方式与本地文件系统上相同
帮助文件:
sftp> help
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] Resumedownload 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
配置实例:
[root@desktop0 ~]# sftp root@172.25.0.11
Connected to 172.25.0.11.
sftp> ls
anaconda-ks.cfg
sftp> pwd
Remote working directory: /root
sftp> ls
anaconda-ks.cfg
sftp> get anaconda-ks.cfg
Fetching /root/anaconda-ks.cfg to anaconda-ks.cfg
/root/anaconda-ks.cfg 100%8619 8.4KB/s 00:00
sftp> put etc.tar.gz
Uploading etc.tar.gz to /root/etc.tar.gz
etc.tar.gz 100% 8541KB 8.3MB/s 00:00
sftp> ls
anaconda-ks.cfg etc.tar.gz
sftp> ls #显示远程目录
anaconda-ks.cfg etc.tar.gz
sftp> lls #显示本地目录
anaconda-ks.cfg etc.tar.gz file1.sh rsc smb_edward.cred test.sh top.txt
sftp> lpwd
Local working directory: /root