rz&sz&scp端对端文件传输整理

rz&sz&scp端对端文件传输整理

rz sz

rz -E file #从本地计算机上传文件到远程主机

sz -E file #从远程主机下载文件到本地计算机

scp (Secure Copy Protocol)

  • 功能: 通过SSH协议在本地和远程主机之间安全地复制文件
bash 复制代码
scp [选项] [源文件或目录] [目标文件或目录]

选项说明

  • -r: 递归复制整个目录
  • -P port: 指定远程主机的SSH端口(注意:-P是大写)
  • -v: 详细模式,输出调试信息
  • -i identity_file: 指定用于SSH连接的私钥文件
  • -q: 安静模式,不显示进度和错误信息
  • -C: 启用压缩在传输过程中

使用示例

1. 将本地文件复制到远程主机

bash 复制代码
scp localfile.txt user@remotehost:/path/to/destination/
  • 这个命令会将本地的localfile.txt文件复制到远程主机remotehost上的指定目录

2. 将本地目录递归复制到远程主机

bash 复制代码
scp -r localdirectory user@remotehost:/path/to/destination/
  • -r选项表示递归复制localdirectory及其内容到远程主机

3. 从远程主机复制文件到本地

bash 复制代码
scp user@remotehost:/path/to/remote/file.txt /local/path/
  • 这个命令将远程主机上的文件file.txt复制到本地指定的路径

4. 从远程主机递归复制目录到本地

bash 复制代码
scp -r user@remotehost:/path/to/remote/directory /local/path/
  • 这个命令将远程主机上的整个目录复制到本地

5. 指定SSH端口进行文件传输

bash 复制代码
scp -P 2222 localfile.txt user@remotehost:/path/to/destination/
  • 如果远程主机的SSH端口是2222,而不是默认的22,可以使用-P选项指定端口

6. 使用SSH密钥文件进行身份验证

bash 复制代码
scp -i ~/.ssh/id_rsa localfile.txt user@remotehost:/path/to/destination/
  • 如果使用私钥文件进行SSH身份验证,使用-i选项指定密钥文件

7. 同时复制多个文件到远程主机

bash 复制代码
scp file1.txt file2.txt user@remotehost:/path/to/destination/
  • 可以在命令中一次指定多个文件进行复制

8. 从远程主机复制多个文件到本地

bash 复制代码
scp user@remotehost:/path/to/remote/file1.txt user@remotehost:/path/to/remote/file2.txt /local/path/
  • 使用多个源文件进行复制

9. 复制文件并重命名

bash 复制代码
scp localfile.txt user@remotehost:/path/to/destination/newfile.txt
  • 将本地文件复制到远程主机,并在远程主机上重命名为newfile.txt

注意事项

  • 使用scp时,需要确保远程主机的SSH服务已启动,并且有访问权限
  • 在传输大文件时,传输速度可能会受到网络带宽的限制
  • 确保SSH密钥或密码的安全,避免数据泄露
相关推荐
java_logo6 分钟前
Webtop Docker 容器化部署指南:基于浏览器的Linux桌面环境
linux·docker·容器·webtop·webtop部署教程·docker部署webtop·linux桌面
Bruce_Liuxiaowei17 分钟前
SSH主机密钥验证失败(Host key verification failed)深度解析与解决方案
运维·网络·ssh
^_scv_^20 分钟前
QEMU-RISCV平台opensbi代码分析(2)
linux·架构·risc-v
core51228 分钟前
Nginx 实战:如何通过代理转发下载中文文件并保留原文件名
运维·nginx·代理·下载·转发
OliverH-yishuihan37 分钟前
在 Windows 上安装 Linux
linux·运维·windows
zclinux_42 分钟前
【Linux】虚拟化的内存气泡
linux·运维·服务器
爱潜水的小L1 小时前
自学嵌入式day33,互斥和同步
linux
tianyuanwo1 小时前
深度解析 - 软件包依赖安装机制与故障排除
服务器·yum·dnf·安装依赖
松涛和鸣1 小时前
DAY33 Linux Thread Synchronization and Mutual Exclusion
linux·运维·服务器·前端·数据结构·哈希算法
A_New_World1 小时前
Linux内核配置、编译、安装
linux