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 |
||
