Linux 命令之 sftp -- 交互式的文件传输程序
文章目錄
- 一、命令介紹
- 二、常用選項(xiàng)
- 三、參考示例
- (一)使用 sftp 連接遠(yuǎn)程主機(jī)
- (二)使用 sftp 上傳文件到遠(yuǎn)程主機(jī)
- (三)使用 sftp 從遠(yuǎn)程主機(jī)下載文件
- (四)查看遠(yuǎn)程主機(jī)的當(dāng)前目錄
- (五)查看本地主機(jī)的當(dāng)前目錄
- (六)查看本地主機(jī)當(dāng)前目錄的內(nèi)容
- (七)切換本地主機(jī)的當(dāng)前目錄
- (八)sftp 支持的全部命令
一、命令介紹
sftp 命令全稱是 Secure File Transfer Protocol(中文譯為:安全文件傳輸協(xié)議),sftp 實(shí)則是一種基于可靠數(shù)據(jù)流(data stream),提供文件存取和管理的網(wǎng)絡(luò)傳輸協(xié)議,在此是一款交互式的文件傳輸程序,sftp 命令的運(yùn)行和使用方式與 ftp 命令相似,但是,sftp 命令對(duì)傳輸?shù)乃行畔⑹褂?ssh 加密,它還支持公鑰認(rèn)證和壓縮等功能。
如果遠(yuǎn)程服務(wù)器自定義了連接的端口,可以使用 -P 參數(shù):
sftp -P remote_port user_name@remote_server_address[:path]
連接成功后將進(jìn)入一個(gè) sftp 的解釋器,可以發(fā)現(xiàn)命令行提示符變成了 sftp>,使用 exit 或者 quit 或者 bye 命令可以退出 sftp 解釋器。
如果連接地址存在 path 并且 path 不是一個(gè)目錄,那么 sftp 會(huì)直接從服務(wù)器端取回這個(gè)文件。
二、常用選項(xiàng)
| -B | buffer_size,指定傳輸文件時(shí)緩沖區(qū)的大小,即指定傳輸 buffer 的大小,更大的 buffer 會(huì)消耗更多的內(nèi)存,默認(rèn)為 32768 bytes |
| -P | port,指定連接的端口號(hào) |
| -l | 使用ssh協(xié)議版本1 |
| -b | 指定批處理文件 |
| -C | 使用壓縮 |
| -o | 指定ssh選項(xiàng) |
| -F | 指定ssh配置文件 |
| -R | num_requests,指定一次能夠容忍多少請(qǐng)求數(shù),即指定一次連接的請(qǐng)求數(shù),可以略微提升傳輸速度,但是會(huì)增加內(nèi)存的使用量 |
| -v | 升高日志等級(jí) |
三、參考示例
(一)使用 sftp 連接遠(yuǎn)程主機(jī)
詳見(jiàn)《Mac OS 使用命令(scp/sftp)將本地文件上傳到遠(yuǎn)程 Linux 服務(wù)器主機(jī)或者從遠(yuǎn)程主機(jī)下載文件到本地主機(jī)》
(二)使用 sftp 上傳文件到遠(yuǎn)程主機(jī)
詳見(jiàn)《Mac OS 使用命令(scp/sftp)將本地文件上傳到遠(yuǎn)程 Linux 服務(wù)器主機(jī)或者從遠(yuǎn)程主機(jī)下載文件到本地主機(jī)》
(三)使用 sftp 從遠(yuǎn)程主機(jī)下載文件
詳見(jiàn)《Mac OS 使用命令(scp/sftp)將本地文件上傳到遠(yuǎn)程 Linux 服務(wù)器主機(jī)或者從遠(yuǎn)程主機(jī)下載文件到本地主機(jī)》
(四)查看遠(yuǎn)程主機(jī)的當(dāng)前目錄
sftp> pwd Remote working directory: /root(五)查看本地主機(jī)的當(dāng)前目錄
sftp> lpwd Local working directory: /Users/liaowenxiong(六)查看本地主機(jī)當(dāng)前目錄的內(nèi)容
查看可見(jiàn)的文件和目錄:
sftp> lls Applications Downloads Pictures Creative Cloud Files Library Public Desktop Movies cookiefile.json Documents Music statistics.json查看所有的文件和目錄,包含隱藏的文件:
sftp> lls -a . .profile .. .putty .CFUserTextEncoding .sogouinput .DS_Store .ssh .ShadowsocksX .subversion .ShadowsocksX-NG .tooling .Trash .viminfo .adobe .webclipse .android .zsh_history .bash_history .zsh_sessions .bash_profile .zshrc .bash_sessions Applications .config Creative Cloud Files .cups Desktop .deliverycenter.installs Documents .deliverycenter.system Downloads .eclipse Library .gervill Movies .local Music .m2 Pictures .myeclipse Public .myeclipse.properties cookiefile.json .oracle_jre_usage statistics.json(七)切換本地主機(jī)的當(dāng)前目錄
使用命令 lcd 切換本地主機(jī)的目錄:
sftp> lpwd Local working directory: /Users/liaowenxiong sftp> lcd desktop sftp> lpwd Local working directory: /Users/liaowenxiong/Desktop(八)sftp 支持的全部命令
輸入命令 help 查看 sftp 支持哪些命令:
sftp> help Available commands: bye Quit sftp cd path Change remote directory to 'path' chgrp [-h] grp path Change group of file 'path' to 'grp' chmod [-h] mode path Change permissions of file 'path' to 'mode' chown [-h] own path Change owner of file 'path' to 'own' df [-hi] [path] Display statistics for current directory orfilesystem containing 'path' exit Quit sftp get [-afpR] 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 切換進(jìn)度表顯示 put [-afpR] local [remote] Upload file pwd Display remote working directory quit Quit sftp reget [-fpR] remote [local] Resume download file rename oldpath newpath Rename remote file reput [-fpR] local [remote] Resume upload file rm path Delete remote file rmdir path Remove remote directory symlink oldpath newpath Symlink remote file 符號(hào)鏈接遠(yuǎn)程文件 version Show SFTP version !command Execute 'command' in local shell 在本地 shell 執(zhí)行命令 ! Escape to local shell 返回到本地 shell ? Synonym for help總結(jié)
以上是生活随笔為你收集整理的Linux 命令之 sftp -- 交互式的文件传输程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 由旧的路由器换新的路由器怎么换如何将旧路
- 下一篇: Linux 命令之 tree -- 以树