linux中SFTP 用法(實現檔案上傳下載)

來源:互聯網
上載者:User

FTP 諸君大概都用過,SFTP 用過的估計比較少。簡單說,它就是 ftp 前加個 secure,通過 ssh 通道在本地及遠程伺服器間進行檔案傳輸,更為安全。

串連

ssh 的串連通常是這樣:

ssh sam@zfanw.com

然後輸入密碼。

sftp 基本就是把 ssh 換作 sftp:

sftp sam@zfanw.com

如果配置了 ssh 的 config 檔案,使用私密金鑰/公開金鑰的形式串連遠程伺服器,則更簡單了:

sftp linode

串連完成後,終端顯示:

sftp >

下載檔案

ftp 主要的作用就是檔案傳輸,sftp 提供的下載檔案命令是 get:

get -r picture
這個命令把 picture 目錄下載到本地。
get sam.png
這個命令把 sam.png 圖片下載到本地。
本地的哪裡??
我們可以藉助 lpwd 命令查看本地的當前工作目錄 – 就是在 pwd 命令前加個 l 表示 local。可以想知,我們同樣可以使用 lcd 來切換本地的工作目錄。
上傳檔案
sftp 提供的上傳命令是 put。
put sam.png
這個命令把本地當前工作目錄下的 sam.png 上傳到遠程伺服器的工作目錄下。
put -r picture
上傳整個目錄檔案。
更多命令
在 sftp > 終端輸入 help 即可以查看 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
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.