`
futeng
  • 浏览: 260612 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

SSH 远程文件/目录传输命令SCP示例详解

阅读更多

需求

  1. 同网段机器之间,如何使用SSH连接快速传输文件(或目录)。
  2. 数据最好以加密方式传输。

解决

SCP命令,采用同ssh的加密方式传输数据,在同个网络内能很方便的跨机器传输数据。

SCP - secure copy (remote file copy program)
scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication.

示例

tips
1. 注意确保文件和目录都存在。
2. @连接用户名和IP,连接IP和路径名。
3. 上传的命令参数顺序:把什么(本地)上传到哪
4. 下载的命令参数顺序:把什么(远程)下载到哪

1. 上传文件

scp 要上传什么文件 以什么用户@上传到什么服务器:的什么位置

[root@CRXJ-COLL-1 src_dir]# scp ./install.log root@10.60.9.2:/root/des_dir/install.log.bak
root@10.60.9.2's password:
install.log                                                                            100%   62KB  62.4KB/s   00:00 
[root@CRXJ-COLL-1 src_dir]#

 

2. 上传整个目录

scp -r 要上传什么目录 以什么用户@上传到什么服务器:的什么位置

-r 递归复制

[root@CRXJ-COLL-1 ~]# scp -r  ./src_dir/ root@10.60.9.2:/root/
root@10.60.9.2's password:
install.log                                                                            100%   62KB  62.4KB/s   00:00   
[root@CRXJ-COLL-1 ~]#

 

3. 下载文件

scp 从什么用户@什么服务器:的什么文件 下载到什么位置

[root@CRXJ-COLL-1 src_dir]# scp root@10.60.9.2:/root/des_dir/install.log.bak /root/src_dir/
root@10.60.9.2's password:
install.log.bak                                                                        100%   62KB  62.4KB/s   00:00   
[root@CRXJ-COLL-1 src_dir]#

 

4. 下载整个目录

scp -r 从什么用户@什么服务器:的什么目录 下载到什么位置

-r 递归复制

 

[root@CRXJ-COLL-1 ~]# scp -r root@10.60.9.2:/root/des_dir/ /root/
root@10.60.9.2's password:
install.log.bak                                                                        100%   62KB  62.4KB/s   00:00   
[root@CRXJ-COLL-1 ~]#

 

5. 可能的错误

  1. ./src_dir: not a regular file 目标文件夹不存在

 

6. 其他可能用到的参数

  1. -p : 指定端口
  2. -v : 显示进度
  3. -C : 压缩选项
  4. -4 : 强行使用 IPV4 地址 .
  5. -6 : 强行使用 IPV6 地址 .
1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics