scp命令
用途 實(shí)現(xiàn)本機(jī)文檔(文件夾)與遠(yuǎn)程機(jī)器的相互拷貝。即:copy from local to remote,也可以copy from remote to local. 是基于ssh實(shí)現(xiàn)的安全保密的傳輸模式。
用法
1>從本地服務(wù)器復(fù)制到遠(yuǎn)程服務(wù)器
(1) 復(fù)制文件:
命令格式:
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個(gè)指定了用戶名,命令執(zhí)行后需要輸入用戶密碼,第1個(gè)僅指定了遠(yuǎn)程的目錄,文件名字不變,第2個(gè)指定了文件名
第3,4個(gè)沒有指定用戶名,命令執(zhí)行后需要輸入用戶名和密碼,第3個(gè)僅指定了遠(yuǎn)程的目錄,文件名字不變,第4個(gè)指定了文件名
實(shí)例:
scp /home/hejianchao/demo/a.tar.gz root@www.Amachine.com:/home/anotherUser/demo
scp /home/hejianchao/demo/b.tar.gz root@www.Amachine.com:/home/anotherUser/b.tar.gz
scp /home/hejianchao/demo/c.tar.gz www.mydomain.com:/home/anotherUser/demo
scp /home/hejianchao/demo/d.tar.gz www.mydomain.com:/home/anotherUser/demo/d.tar.gz
(2) 復(fù)制目錄:
命令格式:
scp -r local_folder remote_username@remote_ip:remote_folder
或者 scp -r local_folder remote_ip:remote_folder
第1個(gè)指定了用戶名,命令執(zhí)行后需要輸入用戶密碼;
第2個(gè)沒有指定用戶名,命令執(zhí)行后需要輸入用戶名和密碼;
實(shí)例:
scp -r /home/hejianchao/demo/ root@www.Amachine.com:/home/anotherUser/demo/
scp -r /home/hejianchao/demo/ www.Amachine.com:/home/anotherUser/demo/
效果:把本機(jī)demo 目錄 復(fù)制 到 遠(yuǎn)程 demo 目錄下。
2>從遠(yuǎn)程服務(wù)器復(fù)制到本地服務(wù)器
從遠(yuǎn)程復(fù)制到本地的scp命令與上面的命令十分類似,只要將從本地復(fù)制到遠(yuǎn)程的命令后面2個(gè)參數(shù)互換順序就行了。
例如:
scp root@www.Amachine.com:/home/anotherUser/demo/a.zip /home/hejianchao/demo/a.zip
scp www.Amachine.com:/home/anotherUser/demo/ -r /home/hejianchao/demo/
更多詳情,參見:man scp.