CentOS, 本機伺服器,ip: 192.168.1.111 Ubuntu, 遠程伺服器,ip: 192.168.1.1121.拷貝遠程伺服器的目錄到本機伺服器 遠程伺服器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
|