怎样使用sftp command line?怎样在sftp里用pem file登陆

sftp是基于ssh的文件传输命令行工具,UNIX系统比如Mac和Linux里都有。各大平台,包括Windows也有图像界面的。还有个叫ftp的工具,是sftp的前辈,功能基本一样。s是secure的意思,就是ftp都是明码传输而sftp加密了。本文主要专注在命令行上面。

如果你需要使用AWS EC2,那么登陆需要用pem file,可以用如下命令

$ sftp -i <pem file name>.pem <user>@<ip>

用pem file的话不需要密码,登陆后进入交互式界面,和shell很像

sftp>

可以看服务器上的文件

sftp> ls

看本地文件

sftp> lls

上传文件

sftp> put <local file path> <remote file path>

上传目录加个-r,代表recursive

sftp> put -r <local file path> <remote file path>

下载文件

sftp> get <remote file path> <local file path> 

同理下载目录用-r

sftp> get -r <remote file path> <local file path> 

帮助就直接问号 ?

sftp> ?
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> bye
# 或者
sftp> exit

或者 Ctrl + d

基本还是一个很容易使用的在本地和服务器传文件的小工具。

Leave a Comment

Your email address will not be published.