我們在工作中,經常會遇到需要向Linux服務傳輸文件的需求,下面總結下常用的幾種方式。
1. rz sz
安裝
# yum 安裝
yum -y install lrzsz
# 源碼安裝
# 地址 https://www.ohse.de/uwe/software/lrzsz.html
使用
# xshell 或 SecureCRT 中
# SecureCRT 中通過 options — session options — X/Y/Zmodem 配置默認上傳/下載目錄
# 選擇文件上傳到服務器
rz
# 下載文件到本地
sz [fileName]
2. scp
使用
# scp 使用ssh連接和加密方式
# 需要安裝 ssh
yum install openssh-clients -y # 客戶端
yum install openssh-server -y # 服務端
# 復制遠程服務器文件到本地
scp -i [identity_file] [remote_username]@[remote_ip]:[remote_file] [local_file]
# 復制本地文件到遠程服務器
scp -i [identity_file] [local_file] [remote_username]@[remote_ip]:[remote_file]
參數說明:
- -1: 強制scp命令使用協(xié)議ssh1
- -2: 強制scp命令使用協(xié)議ssh2
- -4: 強制scp命令只使用IPv4尋址
- -6: 強制scp命令只使用IPv6尋址
- -B: 使用批處理模式(傳輸過程中不詢問傳輸口令或短語)
- -C: 允許壓縮。(將-C標志傳遞給ssh,從而打開壓縮功能)
- -p:保留原文件的修改時間,訪問時間和訪問權限。
- -q: 不顯示傳輸進度條。
- -r: 遞歸復制整個目錄。
- -v:詳細方式顯示輸出。scp和ssh(1)會顯示出整個過程的調試信息。這些信息用于調試連接,驗證和配置問題。
- -c cipher: 以cipher將數據傳輸進行加密,這個選項將直接傳遞給ssh。
- -F ssh_config: 指定一個替代的ssh配置文件,此參數直接傳遞給ssh。
- -i identity_file: 從指定文件中讀取傳輸時使用的密鑰文件,此參數直接傳遞給ssh。
- -l limit: 限定用戶所能使用的帶寬,以Kbit/s為單位。
- -o ssh_option: 如果習慣于使用ssh_config(5)中的參數傳遞方式,
- -P port:注意是大寫的P, port是指定數據傳輸用到的端口號
- -S program: 指定加密傳輸時所使用的程序。此程序必須能夠理解ssh(1)的選項。
3. rsync
文件同步工具
4. ftp
使用
ftp [ip/hostname]
參數說明:
- -d 詳細顯示指令執(zhí)行過程,便于排錯或分析程序執(zhí)行的情形。
- -i 關閉互動模式,不詢問任何問題。
- -g 關閉本地主機文件名稱支持特殊字符的擴充特性。
- -n 不使用自動登陸。
- -v 顯示指令執(zhí)行過程。
5. sftp
使用:
sftp -i [identity_file] [remote_username]@[remote_ip]
參數說明(man sftp):
- -1 Specify the use of protocol version 1.
- -2 Specify the use of protocol version 2.
- -4 Forces sftp to use IPv4 addresses only.
- -6 Forces sftp to use IPv6 addresses only.
- ……
- -i identity_file Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to ssh(1).
- -o ssh_option