zoukankan      html  css  js  c++  java
  • linux 系统 scp命令实现不同计算机之间的文件传输

    1、测试主机PC1、PC2

    root@PC1:/home/test2# ls
    root@PC1:/home/test2# hostname
    PC1
    root@PC1:/home/test2# ifconfig | head -n 3
    ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.3.106  netmask 255.255.255.0  broadcast 192.168.3.255
            inet6 fe80::7006:ea4a:dd5:3fe5  prefixlen 64  scopeid 0x20<link>
    root@PC2:/home/test01# ls
    root@PC2:/home/test01# hostname
    PC2
    root@PC2:/home/test01# ifconfig | head -n 3
    ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.3.105  netmask 255.255.255.0  broadcast 192.168.3.255
            inet6 fe80::a3e7:f07b:9588:b194  prefixlen 64  scopeid 0x20<link>

    2、从本地传输至远端,就是从PC1主机像PC2主机传输文件

    root@PC1:/home/test2# ping -c 3 192.168.3.105     ## 首先保证计算机之间的连通性
    PING 192.168.3.105 (192.168.3.105) 56(84) bytes of data.
    64 bytes from 192.168.3.105: icmp_seq=1 ttl=64 time=2.66 ms
    64 bytes from 192.168.3.105: icmp_seq=2 ttl=64 time=3.06 ms
    64 bytes from 192.168.3.105: icmp_seq=3 ttl=64 time=11.6 ms
    
    --- 192.168.3.105 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2004ms
    rtt min/avg/max/mdev = 2.664/5.789/11.645/4.143 ms
    root@PC1:/home/test2# ls
    root@PC1:/home/test2# seq 5 > test.txt   ## 创建测试数据
    root@PC1:/home/test2# ls
    test.txt
    root@PC1:/home/test2# cat test.txt
    1
    2
    3
    4
    5
    root@PC1:/home/test2# scp test.txt root@192.168.3.105:/home/test01  ##向远端计算机传输文件, 格式: 远端主机的用户名@IP地址:传输指定的目录,如果要传输文件夹,需要添加-r选项
    root@192.168.3.105's password:
    test.txt                                                                                           100%   10     3.4KB/s   00:00

    可在PC2主机/home/test01目录下查看到该文件。

    root@PC2:/home/test01# ls
    test.txt
    root@PC2:/home/test01# cat test.txt
    1
    2
    3
    4
    5

    3、从远端主机传输文件到本地,也就是从PC2传输至PC1

    root@PC1:/home/test2# ls
    root@PC1:/home/test2# scp root@192.168.3.105:/home/test01/test.txt /home/test2  格式: scp  远端用户名@IP地址:文件的绝对路径  指定本地保存的路径,如果要传输文件夹,需要添加-r选项
    root@192.168.3.105's password:
    test.txt                                                                                           100%   10     2.7KB/s   00:00
    root@PC1:/home/test2# ls   ## 实现了传输
    test.txt
    root@PC1:/home/test2# cat test.txt
    1
    2
    3
    4
    5
  • 相关阅读:
    地图相关
    爬虫机器人检测网站
    Git 工作区、暂存区和版本库概念
    linux镜像下载地址
    selenium基本使用
    socket 编程
    视频观看时间统计
    油猴脚本
    (II)第十三节:使用注解创建Dao、Service、Controller Bean 组件
    (II)第十一节:SpEL 表达式
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15721141.html
Copyright © 2011-2022 走看看