linux下使用scp在伺服器之間拷貝檔案

來源:互聯網
上載者:User
  
CentOS, 本機伺服器,ip: 192.168.1.111
Ubuntu, 遠程伺服器,ip: 192.168.1.112

1.拷貝遠程伺服器的目錄到本機伺服器
遠程伺服器192.168.1.112上面/tmp目錄下面有個test目錄,裡面有個檔案名稱為test,內容也為test
root@ubuntu:/tmp# cat test/test 
test

拷貝遠程伺服器192.168.1.112的目錄/tmp/test到目前的目錄下。
[root@CentOS_Test_Server tmp]# scp -r root@192.168.1.112:/tmp/test ./
The authenticity of host '192.168.1.112 (192.168.1.112)' can't be established.
RSA key fingerprint is 64:76:a6:1e:23:76:ec:25:5e:c2:f3:ef:fc:ad:48:7b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.112' (RSA) to the list of known hosts.
root@192.168.1.112's password: 
test                                                                            100%    5     0.0KB/s   00:00 

注意拷貝到本機伺服器後形成的目錄結構為/tmp/test,而不是/tmp/tmp/test,一定要注意,這裡比較容易混淆,經過自己親自測試,再碰到類似的問題心裡就有底了。
[root@CentOS_Test_Server tmp]# ls test/
test

2.拷貝遠程伺服器的檔案到本機伺服器
將1中拷貝過來的目錄test刪除
rm -rf test

[root@CentOS_Test_Server tmp]# ls -l | grep test | grep -v "grep"

拷貝遠程伺服器192.168.1.112的檔案/tmp/test/test到目前的目錄下。
[root@CentOS_Test_Server tmp]# scp root@192.168.1.112:/tmp/test/test ./
root@192.168.1.112's password: 
test                                                                            100%    5     0.0KB/s   00:00
[root@CentOS_Test_Server tmp]# ls -l | grep test | grep -v "grep"
-rw-r--r-- 1 root  root     5 Sep 22 14:07 test

3.拷貝本機伺服器的目錄到遠程伺服器
在/tmp目錄下面建立目錄dir111,在此目錄下建立檔案file111,內容為file111
[root@CentOS_Test_Server tmp]# mkdir dir111
[root@CentOS_Test_Server tmp]# echo 'content111' > dir111/file111
[root@CentOS_Test_Server tmp]# cat dir111/file111
content111

拷貝本機伺服器的目錄dir111到遠程伺服器的目錄/tmp下

與上述1中類似,拷貝到遠程伺服器後形成的目錄結構為/tmp/dir111,而不是/tmp/tmp/dir111,一定要注意,這裡比較容易混淆。

不管拷貝命令是scp -r dir111 root@192.168.1.112:/tmp還是scp -r /tmp/dir111 root@192.168.1.112:/tmp,在遠程伺服器上面產生的目錄結構均一樣,我親自測試過了。

[root@CentOS_Test_Server tmp]# scp -r /tmp/dir111 root@192.168.1.112:/tmp
root@192.168.1.112's password: 
file111                                                                         100%   11     0.0KB/s   00:00    

遠程伺服器192.168.1.112上面的內容
root@ubuntu:/tmp# ls
dir111  test  vmware-root
root@ubuntu:/tmp# cat dir111/file111
content111

4.拷貝本機伺服器的檔案到遠程伺服器
[root@CentOS_Test_Server tmp]# scp dir111/file111 root@192.168.1.112:/tmp
root@192.168.1.112's password: 
file111                                                                         100%   11     0.0KB/s   00:00 

遠程伺服器192.168.1.112上面的內容
root@ubuntu:/tmp# ls
dir111 file111  test  vmware-root
 


      
 
     
  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.