Linux-scp
scp命令
用途
實現本機文檔(文件夾)與遠程機器的相互拷貝。即:copy from local to remote,也可以copy from remote to local. 是基于ssh實現的安全保密的傳輸模式。
用法
1>從本地服務器復制到遠程服務器
(1) 復制文件:
命令格式:
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
或者 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個指定了用戶名,命令執行后需要輸入用戶密碼,第1個僅指定了遠程的目錄,文件名字不變,第2個指定了文件名
第3,4個沒有指定用戶名,命令執行后需要輸入用戶名和密碼,第3個僅指定了遠程的目錄,文件名字不變,第4個指定了文件名
實例:
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) 復制目錄:
命令格式:
scp -r local_folder remote_username@remote_ip:remote_folder
或者 scp -r local_folder remote_ip:remote_folder
第1個指定了用戶名,命令執行后需要輸入用戶密碼;
第2個沒有指定用戶名,命令執行后需要輸入用戶名和密碼;
實例:
scp -r /home/hejianchao/demo/ root@www.Amachine.com:/home/anotherUser/demo/
scp -r /home/hejianchao/demo/ www.Amachine.com:/home/anotherUser/demo/
效果:把本機demo 目錄 復制 到 遠程 demo 目錄下。
2>從遠程服務器復制到本地服務器
從遠程復制到本地的scp命令與上面的命令十分類似,只要將從本地復制到遠程的命令后面2個參數互換順序就行了。
例如:
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.
posted on 2013-04-09 23:17 hejianchao 閱讀(160) 評論(0) 編輯 收藏 所屬分類: 一天一命令