怎樣使用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.