scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的。可能会稍微影响一下速度。当你服务器硬盘变为只读 read only system时,用scp可以帮你把文件移出来。另外,scp还非常不占资源,不会提高多少系统负荷,在这一点上,rsync就远远不及它了。虽然 rsync比scp会快一点,但当小文件众多的情况下,rsync会导致硬盘I/O非常高,而scp基本不影响系统正常使用。

1.命令格式:

scp [参数] [原路径] [目标路径]

2.命令功能:

scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令。linux的scp命令可以在linux服务器之间复制文件和目录。

3.命令参数:

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

4.使用实例:

scp命令的实际应用概述:

从本地服务器复制到远程服务器:

(1) 复制文件:

命令格式:

scp local_file remote_username@remote_ip:remote_folder

或者

scp local_file remote_username@remote_ip:remote_file

或者

scp local_file remote_ip:remote_folder

或者

scp local_file remote_ip:remote_file

第1,2个指定了用户名,命令执行后需要输入用户密码,第1个仅指定了远程的目录,文件名字不变,第2个指定了文件名

第3,4个没有指定用户名,命令执行后需要输入用户名和密码,第3个仅指定了远程的目录,文件名字不变,第4个指定了文件名

(2) 复制目录:

命令格式:

scp -r local_folder remote_username@remote_ip:remote_folder

或者

scp -r local_folder remote_ip:remote_folder

第1个指定了用户名,命令执行后需要输入用户密码;

第2个没有指定用户名,命令执行后需要输入用户名和密码;

从远程服务器复制到本地服务器:

从远程复制到本地的scp命令与上面的命令雷同,只要将从本地复制到远程的命令后面2个参数互换顺序就行了。

实例1:从远处复制文件到本地目录

命令:

scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/

输出:


[root@localhost ~]# cd /opt/soft/ [root@localhost soft]# ll 总计 80072 drwxr-xr-x 12 root root     4096 09-21 18:40 fms3.5 drwxr-xr-x  3 root root     4096 09-21 17:58 fms4.5 drwxr-xr-x 10 root root     4096 10-30 17:15 jdk1.6.0_16 drwxr-xr-x 10 root root     4096 09-17 19:27 jdk1.6.0_16.bak -rwxr-xr-x  1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bin drwxrwxrwx  2 root root     4096 09-21 01:16 mysql drwxr-xr-x  3 root root     4096 09-21 18:40 setup_file drwxr-xr-x  9 root root     4096 09-17 19:23 tomcat6.0.32 drwxr-xr-x  9 root root     4096 2012-08-14 tomcat_7.0 [root@localhost soft]# scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/ root@192.168.120.204's password: nginx-0.5.38.tar.gz                                                                               100%  479KB 478.7KB/s   00:00    [root@localhost soft]# ll 总计 80556 drwxr-xr-x 12 root root     4096 09-21 18:40 fms3.5 drwxr-xr-x  3 root root     4096 09-21 17:58 fms4.5 drwxr-xr-x 10 root root     4096 10-30 17:15 jdk1.6.0_16 drwxr-xr-x 10 root root     4096 09-17 19:27 jdk1.6.0_16.bak -rwxr-xr-x  1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bin drwxrwxrwx  2 root root     4096 09-21 01:16 mysql -rw-r--r--  1 root root   490220 03-15 09:11 nginx-0.5.38.tar.gz drwxr-xr-x  3 root root     4096 09-21 18:40 setup_file drwxr-xr-x  9 root root     4096 09-17 19:23 tomcat6.0.32 drwxr-xr-x  9 root root     4096 2012-08-14 tomcat_7.0 [root@localhost soft]#

说明:

从192.168.120.204机器上的/opt/soft/的目录中下载nginx-0.5.38.tar.gz 文件到本地/opt/soft/目录中

实例2:从远处复制到本地

命令:

scp -r root@192.168.120.204:/opt/soft/mongodb /opt/soft/

输出:


[root@localhost soft]# ll 总计 80556 drwxr-xr-x 12 root root     4096 09-21 18:40 fms3.5 drwxr-xr-x  3 root root     4096 09-21 17:58 fms4.5 drwxr-xr-x 10 root root     4096 10-30 17:15 jdk1.6.0_16 drwxr-xr-x 10 root root     4096 09-17 19:27 jdk1.6.0_16.bak -rwxr-xr-x  1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bin drwxrwxrwx  2 root root     4096 09-21 01:16 mysql -rw-r--r--  1 root root   490220 03-15 09:11 nginx-0.5.38.tar.gz drwxr-xr-x  3 root root     4096 09-21 18:40 setup_file drwxr-xr-x  9 root root     4096 09-17 19:23 tomcat6.0.32 drwxr-xr-x  9 root root     4096 2012-08-14 tomcat_7.0 [root@localhost soft]# scp -r root@192.168.120.204:/opt/soft/mongodb /opt/soft/ root@192.168.120.204's password: mongodb-linux-i686-static-1.8.5.tgz                                                               100%   28MB  28.3MB/s   00:01    README                                                                                            100%  731     0.7KB/s   00:00    THIRD-PARTY-NOTICES                                                                               100% 7866     7.7KB/s   00:00    mongorestore                                                                                      100% 7753KB   7.6MB/s   00:00    mongod                                                                                            100% 7760KB   7.6MB/s   00:01    mongoexport                                                                                       100% 7744KB   7.6MB/s   00:00    bsondump                                                                                          100% 7737KB   7.6MB/s   00:00    mongofiles                                                                                        100% 7748KB   7.6MB/s   00:01    mongostat                                                                                         100% 7808KB   7.6MB/s   00:00    mongos                                                                                            100% 5262KB   5.1MB/s   00:01    mongo                                                                                             100% 3707KB   3.6MB/s   00:00    mongoimport                                                                                       100% 7754KB   7.6MB/s   00:00    mongodump                                                                                         100% 7773KB   7.6MB/s   00:00    GNU-AGPL-3.0                                                                                      100%   34KB  33.7KB/s   00:00    [root@localhost soft]# ll 总计 80560 drwxr-xr-x 12 root root     4096 09-21 18:40 fms3.5 drwxr-xr-x  3 root root     4096 09-21 17:58 fms4.5 drwxr-xr-x 10 root root     4096 10-30 17:15 jdk1.6.0_16 drwxr-xr-x 10 root root     4096 09-17 19:27 jdk1.6.0_16.bak -rwxr-xr-x  1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bin drwxr-xr-x  3 root root     4096 03-15 09:18 mongodb drwxrwxrwx  2 root root     4096 09-21 01:16 mysql -rw-r--r--  1 root root   490220 03-15 09:11 nginx-0.5.38.tar.gz drwxr-xr-x  3 root root     4096 09-21 18:40 setup_file drwxr-xr-x  9 root root     4096 09-17 19:23 tomcat6.0.32 drwxr-xr-x  9 root root     4096 2012-08-14 tomcat_7.0 [root@localhost soft]#

说明:

从192.168.120.204机器上的/opt/soft/中下载mongodb 目录到本地的/opt/soft/目录来。

实例3:上传本地文件到远程机器指定目录

命令:

scp /opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest

输出:


上传前目标机器的目标目录: [root@localhost soft]# cd scptest/ [root@localhost scptest]# ll 总计 0 [root@localhost scptest]# ll 本地机器上传: [root@localhost soft]# scp /opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest root@192.168.120.204's password: nginx-0.5.38.tar.gz                                                                               100%  479KB 478.7KB/s   00:00    [root@localhost soft]# 上传后目标机器的目标目录: [root@localhost scptest]# ll 总计 484 -rw-r--r-- 1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz [root@localhost scptest]#

说明:

复制本地opt/soft/目录下的文件nginx-0.5.38.tar.gz 到远程机器192.168.120.204的opt/soft/scptest目录

实例4:上传本地目录到远程机器指定目录

命令:

scp -r /opt/soft/mongodb root@192.168.120.204:/opt/soft/scptest

输出:


上传前目标机器的目标目录: [root@localhost ~]# cd /opt/soft/scptest/ [root@localhost scptest]# ll 总计 484 -rw-r--r-- 1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz [root@localhost scptest]# 本地机器上传: [root@localhost ~]# scp -r /opt/soft/mongodb root@192.168.120.204:/opt/soft/scptest root@192.168.120.204's password: mongodb-linux-i686-static-1.8.5.tgz                                                               100%   28MB  28.3MB/s   00:01    README                                                                                            100%  731     0.7KB/s   00:00    THIRD-PARTY-NOTICES                                                                               100% 7866     7.7KB/s   00:00    mongorestore                                                                                      100% 7753KB   7.6MB/s   00:00    mongod                                                                                            100% 7760KB   7.6MB/s   00:01    mongoexport                                                                                       100% 7744KB   7.6MB/s   00:00    bsondump                                                                                          100% 7737KB   7.6MB/s   00:00    mongofiles                                                                                        100% 7748KB   7.6MB/s   00:00    mongostat                                                                                         100% 7808KB   7.6MB/s   00:01    mongos                                                                                            100% 5262KB   5.1MB/s   00:00    mongo                                                                                             100% 3707KB   3.6MB/s   00:00    mongoimport                                                                                       100% 7754KB   7.6MB/s   00:01    mongodump                                                                                         100% 7773KB   7.6MB/s   00:00    GNU-AGPL-3.0                                                                                      100%   34KB  33.7KB/s   00:00    [root@localhost ~]# 上传后目标机器的目标目录: [root@localhost scptest]# ll 总计 488 drwxr-xr-x 3 root root   4096 03-15 09:33 mongodb -rw-r--r-- 1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz [root@localhost scptest]#

scp命令:服务器间远程复制代码的更多相关文章

  1. scp 服务器之间远程复制

    从本地服务器复制到远程服务器: (1) 复制文件: 命令格式: scp local_file remote_username@remote_ip:remote_folder 或者 scp local_ ...

  2. Linux 常用命令 服务器间scp 用户 export 创建文件、软连接

    获取外网ip curl icanhazip.com 服务器间的 文件 复制 scp root@ip:/源目录 目标目录 软连接 查看软连接 ls -li 创建软连接 ln -s 源文件 目标文件 -s ...

  3. Linux使用scp命令进行文件远程拷贝详解

    前言 scp是 secure copy的缩写, scp是Linux系统下基于ssh登陆进行安全的远程文件拷贝命令.Linux的scp命令可以在Linux服务器之间复制文件和目录. 使用语法: scp  ...

  4. [Linux] scp本地服务器和远程服务器拷贝文件

    上传本地文件到服务器scp 本地路径 用户名@远程服务器ip:远程路径 下载文件 scp 用户名@远程服务器ip:远程路径 本地路径-r 是上传下载本地目录到远程 远程文件

  5. 使用pscp实现Windows 和 Linux服务器间远程拷贝文件

    转自:http://www.linuxidc.com/Linux/2012-05/60966.htm 在工作中,每次部署应用时都需要从本机Windows服务器拷贝文件到Linux上,有时还将Linux ...

  6. windows下使用Git Bash命令行克隆远程仓库代码

    此处使用的代码托管平台是GitLab,相比GitHub来说,它可以设置免费的私有仓库,哈哈,妈妈再也不用担心我的源码泄露了!1.切换到本地的工作目录,我的目录是: cd /d/coder/websit ...

  7. scp windows 和 linux 远程复制 (双向)

    一下命令在cmd中 从w -> l : scp D:\a.txt root@192.168.2.113:/home/a 从l -> w: scp root@192.168.2.113:/h ...

  8. linux scp命令参数及用法详解--linux远程复制拷贝命令使用实例【转】

    转自:http://blog.csdn.net/jiangkai_nju/article/details/7338177 一般情况,本地网络跟远程网络进行数据交抱,或者数据迁移,常用的有三种方法,一是 ...

  9. linux 的 scp 命令 可以 在 linux 之间复制 文件 和 目录

    转自:http://blog.csdn.net/snlying/article/details/6184102 Linux系统中scp命令的用法. scp就是secure copy的简写,用于在lin ...

随机推荐

  1. 微信小程序入门实例之记事本

    主要实现思想都在代码的注释中,项目源码见github 首先上项目目录 app.js文件代码如下: //app.js App({ onLaunch: function() { //调用API从本地缓存中 ...

  2. 用js来实现那些数据结构及算法—目录

    首先,有一点要声明,下面所有文章的所有内容的代码,都不是我一个人独立完成的,它们来自于一本叫做<学习JavaScript数据结构和算法>(第二版),人民邮电出版社出版的这本书.github ...

  3. 网络数据包信息收集工具ferret-sidejack

    网络数据包信息收集工具ferret-sidejack   网络数据包传递用户的各种操作和对应的信息.但是由于各种数据混在一起,不利于渗透测试人员分析.Kali Linux提供了一款信息搜集工具ferr ...

  4. centos 7下安装MySQL5.7 的安装和配置

    原文链接:  http://blog.csdn.net/xyang81/article/details/51759200 安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置Y ...

  5. Bugzilla Error message: couldn't create child process: 720003: index.cgi

    two steps is try to fix this issue. 1. Turn off the windowns firewall 2. Register the perl to the sy ...

  6. 用AB对Webservice做压力测试

    AB工具下载 AB工具介绍见 web压力测试工具 下载ab工具后放到任意目录下,从命令行打开ab.exe 使用以下命令测试Webservice ab -c 100 -n 1000 -p zip.txt ...

  7. LPC43xx MCU PIN Name and GPIO PIN Name Table

    //--------------------------------------------------------------------------------+ // LPC43xx Pin N ...

  8. CoreSight™ Technology

    ARM Cortex-M processor-based devices use the ARM CoreSight technology which introduces powerful new  ...

  9. jquery-chosen设置默认值

    <span style="font-size:18px;"> <select id="select1" class="select1 ...

  10. 《Go学习笔记 . 雨痕》类型

    一.基本类型 清晰完备的预定义基础类型,使得开发跨平台应用时无须过多考虑符合和长度差异. 类型 长度 默认值 说明 bool 1 false   byte 1 0 uint8 int, uint 4, ...