我们在工作中,经常会遇到需要向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命令使用协议ssh1
- -2: 强制scp命令使用协议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 详细显示指令执行过程,便于排错或分析程序执行的情形。
- -i 关闭互动模式,不询问任何问题。
- -g 关闭本地主机文件名称支持特殊字符的扩充特性。
- -n 不使用自动登陆。
- -v 显示指令执行过程。
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