zoukankan      html  css  js  c++  java
  • 【Linux命令】scp

    scp是 secure copy的缩写。scp命令用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝。scp 命令不局限于linux ,因为在windows 下也有(windows 10 专业版也有)。 因此可以用于windows 和 Linux 主机间数据传输

    环境:linux (ubuntu 系统),windows( windows10 专业版 )

    【注】在centos 下也可以(包括从windows 到centos,还是centos 到其它linux 发行版)

               windows 和 linux 下scp 命令的参数选项是一样的

    参数说明:

    -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)的选项。

    实例:

    从本地复制到远程

    这里分别使用windows 和 Linux 下文件传输
    命令格式: 

    scp local_file remote_username@remote_ip:remote_folder 
    或者 
    scp local_file remote_username@remote_ip:remote_file 

     指定端口号:

    scp -P  remote_port  local_filename  remote_username@remote_ip:remote_folder
    
    #示例:
    scp  -P 22 ncWrite*  root@10.4.71.149:/han/dio/dio/src
    

    从远程复制到本地

    scp -P  remote_port  remote_username@remote_ip:remote_folder  local_folder
    
    #示例:
    scp  -P 22  root@10.4.71.149:/han/dio/dio/src/ncWrite*  /home/writedisk/
    

      

    报错示例:

    1. --"not a regular file"

    在终端执行 

     scp -P 5557 Release root@10.2.25.186:/backupsoft

    scp -P 5557 Release root@10.2.25.186:/backupsoft
    

    出现报错: 

    Release: not a regular file

    解决方法: 

       在文件前面加上 -r ,表示拷贝整个文件目录。

    scp 实现 Windows 和 Linux 互传

    为了进行系统维护操作,有时需要再windows和linux或Unix系统之间互传文件,虽然有很多工具可以实现该功能,但我还是觉得命令行来的方便快捷,起初使用linux的scp命令,总是不成功,网上也没有相关介绍,经过几次努力之后,终于成功的摸索出了scp命令在写windows的路径时的写法,于是马上下了出来,与大家分享:

    从linux系统复制文件到windows系统:scp /oracle/a.txt  administrator@192.168.3.181:/d:/

    在linux环境下,将windows下的文件复制到linux系统中:scp administrator@192.168.3.181:/d:/test/config.ips  /oracle

    注意:因为 windows 系统本身不支持ssh协议,所以,要想上面的命令成功执行,必须在 windows 客户端安装ssh for windows的客户端软件,比如winsshd,使windows系统支持ssh协议才行。

    linux 到 linux :

    scp source  destination_username@destination_ip:destination_filepath   #注意#目的地的url路径中不要漏掉冒号。

  • 相关阅读:
    [C++] split string by string
    工作三个月心得经验
    Ubuntu Command-Line: Enable Unlimited Scrolling in the Terminal
    What is the PPA and How to do with it ?
    WCF vs ASMX WebService
    The ShortCuts in the ADT (to be continued)
    when does the View.ondraw method get called
    Browsing Storage Resources with Server Explorer
    Get start with Android development
    C++ Frequently asking question
  • 原文地址:https://www.cnblogs.com/SchrodingerDoggy/p/13880773.html
Copyright © 2011-2022 走看看