首页 > 代码库 > LINUX SCP 远程 文件 拷贝

LINUX SCP 远程 文件 拷贝

首先要确保两台机子直接IP能够互相ping通




然后使用SCP命令从第一台主机向第二台主机拷贝文件

scp src chiwei@192.168.8.144:/home/chiwei/mydisk/buffer_scp_file


ssh: connect to host 192.168.8.144 port 22: Connection refused
lost connection


检查远程主机没有安装sshd

chiwei@chiwei-VirtualBox:~/mydisk/buffer_scp_file$ sshd
程序“sshd”尚未安装。 您可以使用以下命令安装:
sudo apt-get install openssh-server
chiwei@chiwei-VirtualBox:~/mydisk/buffer_scp_file$ sudo apt-get install openssh-server

安装完成之后开始传输文件,这里我是传输文件夹,将文件夹下文件都传输过去,所以用了-r选项,不用该选项的话只能传文件

[root@localhost /mydisk/eclispe_workspace/java]# scp -r src chiwei@192.168.8.144:/home/chiwei/mydisk/buffer_scp_file
chiwei@192.168.8.144's password: 
logintest.txt                                 100%  977     1.0KB/s   00:00    
ClassLoaderTest.java                          100%   80     0.1KB/s   00:00    
Test.java                                     100%  298     0.3KB/s   00:00    
FileReadWriteByMemcached.java                 100%  139     0.1KB/s   00:00    
Client.java                                   100%  981     1.0KB/s   00:00    
ObjectAnalyzer.java                           100% 3738     3.7KB/s   00:00    
Utils.java                                    100% 5703     5.6KB/s   00:00    
TestQuick.java                                100% 1481     1.5KB/s   00:00    
TestAndPassportValidate.java                  100% 1348     1.3KB/s   00:00    
UtilsTest.java                                100%  283     0.3KB/s   00:00    
Test.java                                     100%  225     0.2KB/s   00:00    
TransferRunnable.java                         100%  614     0.6KB/s   00:00    
Bank.java                                     100% 1041     1.0KB/s   00:00    
UnSyncBankTest.java                           100%  468     0.5KB/s   00:00    
Test.java                                     100%  124     0.1KB/s   00:00    
RSAUtils.java                                 100% 7691     7.5KB/s   00:00    
RSATest.java                                  100% 1980     1.9KB/s   00:00    
Base64Utils.java                              100% 1924     1.9KB/s   00:00    
Test.java                                     100% 2727     2.7KB/s   00:00    
[root@localhost /mydisk/eclispe_workspace/java]# 
到远程主机对应的目录去查看
chiwei@chiwei-VirtualBox:~/mydisk/buffer_scp_file$ ls
src
chiwei@chiwei-VirtualBox:~/mydisk/buffer_scp_file$ cd src/
chiwei@chiwei-VirtualBox:~/mydisk/buffer_scp_file/src$ ls
classloader  jvm            memcached  rsa       thread
demo         logintest.txt  reflect    safedemo
chiwei@chiwei-VirtualBox:~/mydisk/buffer_scp_file/src$ 


以上是本机传文件到远程主机,下面再来试试从远程主机拷贝文件到本机

[root@localhost /mydisk/eclispe_workspace/java]# scp chiwei@192.168.8.144:/home/chiwei/mydisk/buffer_scp_file/demo.txt /mydisk/
chiwei@192.168.8.144's password: 
demo.txt                                      100%   14     0.0KB/s   00:00    
[root@localhost /mydisk/eclispe_workspace/java]# 

本机查看相应目录

[root@localhost /mydisk]# ls
<span style="color:#ff0000;"><strong>demo.txt</strong></span>           hadoop             local_repo  normandy_config  software
eclispe_workspace  learning_material  maven_repo  service
[root@localhost /mydisk]# 

很实用,很简单的命令!










LINUX SCP 远程 文件 拷贝