在Linux中采用sftp(Secure File Transfer Protocol)
为传输文件提供一种安全的网络的加密方法。本文介绍如何使用sftp
做文件传输(与ftp基本类似)。
连接远程linux
sftp <user>@<ip>
操作远程服务器
ls
显示远端主机的列表cd
切换远程的工作目录pwd
显示远程的工作目录
操作本地服务器
lls
显示本地主机的列表lcd
切换本地的工作目录lpwd
查看本地目录信息
上传下载文件
get
从远程服务器下载数据(单个文件)mget
下载多个文件put
从本地服务器上传数据(单个文件)mput
上传多个文件
查看帮助
sftp> help
$ sftp root@b1.xiexianbin.cn
Connected to root@b1.xiexianbin.cn.
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 [-afPpRr] remote [local] Download file
reget [-fPpRr] remote [local] Resume download file
reput [-fPpRr] [local] remote Resume upload 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 [-afPpRr] 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
示例
查看路径
sftp> pwd # Display remote working directory
Remote working directory: /root
sftp> lpwd # Print local working directory
sftp> lpwd
Local working directory: /Users/xiexianbin/
sftp>
上传文件
put -r <本地路径> <远程路径>
sftp> put -r hbxctl /root
Uploading hbxctl to /root/hbxctl
hbxctl 100% 2565 20.8KB/s 00:00
sftp>
上传文件夹
put -r <本地文件夹/*> <远程路径/新建文件夹/>
下载文件
get -r <远程路径> <本地路径>
sftp> get -r /root/themes themes
下载文件夹
get -r <远程路径/文件夹/*> <本地路径/新建文件夹/>
退出
exit