1. 程式人生 > 其它 >sftp常用命令介紹

sftp常用命令介紹

技術標籤:Databaselinuxftp後端

sftp是Secure FileTransferProtocol的縮寫,安全檔案傳送協議。可以為傳輸檔案提供一種安全的加密方法。sftp與 ftp有著幾乎一樣的語法和功能。SFTP為 SSH的一部分,是一種傳輸檔案至Blogger伺服器的安全方式。其實在SSH軟體包中,已經包含了一個叫作SFTP(Secure File TransferProtocol)的安全檔案傳輸子系統,SFTP本身沒有單獨的守護程序,它必須使用sshd守護程序(埠號預設是22)來完成相應的連線操作,所以從某種意義上來說,SFTP並不像一個伺服器程式,而更像是一個客戶端程式。SFTP同樣是使用加密傳輸認證資訊和傳輸的資料,所以,使用SFTP是非常安全的。但是,由於這種傳輸方式使用了加密/解密技術,所以傳輸效率比普通的FTP要低得多,如果您對網路安全性要求更高時,可以使用SFTP代替FTP。

SFTP命令常用選項sftp即secure ftp,是一個互動式檔案傳輸程式。它類似於ftp,但它進行加密傳輸,比FTP有更高的安全性。
在這裡插入圖片描述

1. sftp [email protected]

  • 你要用sftp, 當然得登入到sftp伺服器啊, 在linux的shell中執行上面的命令後, linux shell會提示使用者輸入密碼, 我們就輸入password吧。 這樣就成功建立了sftp連線。

2. help

  • 建立連線後, linux shell中的$程式設計了sftp>, 這也對。 現在執行以下help, 可以看看sftp支援哪些命令。
// A code block
Available commands:
ascii                          Set transfer mode to ASCII
binary                         Set transfer mode to binary
cd path                        Change remote directory to 'path'
detail remote-path             Display system information about remote
                                 file or folder
ldetail local-path             Display system information about local
                                 file or folder
lcd path                       Change local directory to 'path'
chgrp group path               Change group of file 'path' to 'group'
chmod mode path                Change permissions of file 'path' to 'mode'
chown owner path               Change owner of file 'path' to 'owner'
exit                           Quit sftp
help                           Display this help text
include filename               Include commands from 'filename'
                                 Alternate: < filename
get [-a | -b] remote-path      Download file
                                 force ascii (-a) or binary (-b) mode
ln [-s] existingpath linkpath  Hardlink / symlink remote file
ls [options] [path]            Display remote directory listing
lls [options] [path]           Display local directory listing
mkdir path                     Create remote directory
lmkdir path                    Create local directory
mv oldpath newpath             Move remote file
open [
[email protected]
]host[:port] Connect to remote host put [-a | -b] local-path Upload file force ascii (-a) or binary (-b) mode pwd Display remote working directory lpwd Print local working directory quit Quit sftp rmdir path Remove remote directory lrmdir path Remove local directory rm path Delete remote file lrm path Delete local file su username Substitutes the current user This is only supported with VShell for Windows 3.5 or later. type [transfer-mode] Display or set file transfer mode view remote-path Download and open file version Display protocol version

3. pwd和lpwd

  • pwd是看遠端伺服器的目錄, 即sftp伺服器預設的當前目錄。 lpwd是看linux本地目錄。

4. ls和lls

  • ls是看sftp伺服器下當前目錄下的東東, lls是看linux當前目錄下的東東。

5. put a.txt

  • 這個是把linux當前目錄下的a.txt檔案上傳到sftp伺服器的當前目錄下。
    在這裡插入圖片描述

6. get b.txt

  • 這個是把sftp伺服器當前目錄下的b.txt檔案下載到linux當前目錄下。
    在這裡插入圖片描述

7. !command

  • 這個是指在linux上執行command這個命令, 比如!ls是列舉linux當前目錄下的東東, !rm a.txt是刪除linux當前目錄下的a.txt檔案。
  • 這個命令非常非常有用, 因為在sftp> 後輸入命令, 預設值針對sftp伺服器的, 所以執行rm a.txt刪除的是sftp伺服器上的a.txt檔案, 而非本地的linux上的a.txt檔案。

8. exit和quit

  • 退出。

總之, 連線後, 有一個help命令, 足矣足矣。