博客專欄

        EEPW首頁 > 博客 > linux之間的文件互傳-scp命令

        linux之間的文件互傳-scp命令

        發布人:電子禪石 時間:2019-11-20 來源:工程師 發布文章

        scp是secure copy的簡寫,用于在Linux下進行遠程拷貝文件或目錄的命令,基于ssh登陸進行安全的遠程文件拷貝命令,因此其傳輸是加密的。scp占用資源非常少,并不會提高多少系統負荷,在這一點上,另一個命令rsync就遠遠不及它了。雖然 rsync比scp會快一點,但當小文件眾多的情況下,rsync會導致硬盤I/O非常高,而scp基本不影響系統正常使用。

        重點:scp  /nfsroot/NFS_Test/spi_test root@192.168.1.227:/home/spitest

        777.png

        命令參數參數說明
        -1強制scp命令使用協議ssh1
        -2強制scp命令使用協議ssh2
        -4強制scp命令只使用IPv4尋址
        -6強制scp命令只使用IPv6尋址
        -B使用批處理模式(傳輸過程中不詢問傳輸口令或短語)
        -C允許壓縮。(將-C標志傳遞給ssh,從而打開壓縮功能)
        -p保留原文件的修改時間,訪問時間和訪問權限。
        -q不顯示傳輸進度條。
        -r遞歸復制整個目錄。
        -v詳細方式顯示輸出。scp和ssh(1)會顯示出整個過程的調試信息。這些信息用于調試連接,驗證和配置問題。
        -c cipher以cipher將數據傳輸進行加密,這個選項將直接傳遞給ssh。
        -F ssh_config指定一個替代的ssh配置文件,此參數直接傳遞給ssh。
        -i identity_file從指定文件中讀取傳輸時使用的密鑰文件,此參數直接傳遞給ssh。
        -l limit限定用戶所能使用的帶寬,以Kbit/s為單位。
        -P port注意是大寫的P, port是指定數據傳輸用到的端口號。
        -S program指定加密傳輸時所使用的程序。此程序必須能夠理解ssh(1)的選項。
        應用實例從本地服務器復制到遠程服務器復制文件
        • 命令格式scp local_file remote_username@remote_ip:remote_folder,復制到遠程的文件夾中

        # 本地使用命令[root@virtue ~]# scp 1.txt root@172.16.20.38:/tmp/The authenticity of host '172.16.20.38 (172.16.20.38)' can't be established.ECDSA key fingerprint is SHA256:z8KeBlt/fTyXBAibRQk0kGevF9E8HgNvBB6bLJDw5zY.ECDSA key fingerprint is MD5:b5:b6:90:c7:70:46:06:aa:44:3d:35:74:03:88:ec:f7.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '172.16.20.38' (ECDSA) to the list of known hosts.root@172.16.20.38's password: 1.txt                                                                                  100%   37    23.6KB/s   00:00# 遠程計算機中顯示[root@ide ~]# ll /tmp/1.txt -rw-r--r--. 1 root root 37 1月  17 13:40 /tmp/1.txt
        • 命令格式scp local_file remote_username@remote_ip:remote_file,指定復制的文件名

        # 本地使用命令[root@virtue ~]# scp 1.txt root@172.16.20.38:/tmp/2.txt
        root@172.16.20.38's password: 1.txt                                                                                  100%   37    21.9KB/s   00:00    # 遠程計算機中顯示[root@ide ~]# ll /tmp/2.txt 
        -rw-r--r--. 1 root root 37 1月  17 13:43 /tmp/2.txt[root@ide ~]# diff /tmp/1.txt /tmp/2.txt 
        [root@ide ~]#
        • 命令格式scp local_file remote_ip:remote_folder,使用本機登錄用戶作為用戶名傳輸文件,復制文件到指定文件夾

        # 本地使用命令[root@virtue ~]# scp 1.txt 172.16.20.38:/tmp/root@172.16.20.38's password: 1.txt                                                                                  100%   37    50.8KB/s   00:00    # 遠程計算機中顯示[root@ide ~]# ll /tmp/1.txt 
        -rw-r--r--. 1 root root 37 1月  17 13:47 /tmp/1.txt

        可以看到,文件被直接進行了覆蓋,沒有提示

        • 命令格式scp local_file remote_ip:remote_file,使用本機登錄用戶作為用戶名傳輸文件,指定復制的文件名

        # 本地使用命令[root@virtue ~]# scp 1.txt 172.16.20.38:/tmp/3.txt
        root@172.16.20.38's password: 1.txt                                                                                  100%   37     7.5KB/s   00:00    # 遠程計算機中顯示[root@ide ~]# ll /tmp/3.txt 
        -rw-r--r--. 1 root root 37 1月  17 13:52 /tmp/3.txt[root@ide ~]# diff /tmp/1.txt /tmp/3.txt 
        [root@ide ~]#
        復制目錄

        與復制文件的命令格式基本相同,只不過需要增加-r參數

        • 命令格式scp -r local_folder remote_username@remote_ip:remote_folder,目錄整體復制到遠程目錄內。

        # 本地使用命令[root@virtue ~]# scp -P 22 -r script root@172.16.20.38:/tmp
        root@172.16.20.38's password: kernel.txt                                                                             100%   59MB  80.0MB/s   00:00    modify.py                                                                              100%  171   312.5KB/s   00:00    ping.sh                                                                                100%  116   164.5KB/s   00:00    setup.sh                                                                               100%  443   578.1KB/s   00:00    # 遠程計算機中顯示[root@ide ~]# ll /tmp/script/總用量 60428-rw-r--r--. 1 root root 61865984 1月  17 13:58 kernel.txt-rw-r--r--. 1 root root      171 1月  17 13:58 modify.py-rw-r--r--. 1 root root      116 1月  17 13:58 ping.sh-rw-r--r--. 1 root root      443 1月  17 13:58 setup.sh[root@ide ~]#
        • 命令格式scp local_file remote_ip:remote_folder,使用本機登錄用戶作為用戶名傳輸文件,復制目錄到遠程目錄內。

        # 本地使用命令[root@virtue ~]# scp -P 22 -r script 172.16.20.38:/tmp
        root@172.16.20.38's password: kernel.txt                                                                             100%   59MB  79.4MB/s   00:00    modify.py                                                                              100%  171   294.9KB/s   00:00    ping.sh                                                                                100%  116   205.7KB/s   00:00    setup.sh                                                                               100%  443   991.4KB/s   00:00    # 遠程計算機中顯示[root@ide ~]# ll /tmp/script/總用量 60428-rw-r--r--. 1 root root 61865984 1月  17 14:01 kernel.txt-rw-r--r--. 1 root root      171 1月  17 14:01 modify.py-rw-r--r--. 1 root root      116 1月  17 14:01 ping.sh-rw-r--r--. 1 root root      443 1月  17 14:01 setup.sh

        可以看到,目錄被直接進行了覆蓋,也沒有提示

        從遠程服務器復制到本地服務器

        從遠程復制到本地的scp命令與上面的命令雷同,只要將從本地復制到遠程的命令后面2個參數互換順序就行了

        復制文件
        # 指定文件名[root@virtue ~]# scp 172.16.20.38:/tmp/1.txt 1.txt 
        root@172.16.20.38's password: 1.txt                                                                                  100%   37    47.1KB/s   00:00    [root@virtue ~]# ll 1.txt 
        -rw-r--r--. 1 root root 37 1月  17 14:02 1.txt# 指定保存路徑(本地路徑是當前目錄,命令最后有一個.目錄符號)[root@virtue ~]# scp 172.16.20.38:/tmp/1.txt .root@172.16.20.38's password: 1.txt                                                                                  100%   37    32.6KB/s   00:00    [root@virtue ~]# ll 1.txt 
        -rw-r--r--. 1 root root 37 1月  17 14:03 1.txt

        可以看到,無論那種復制方式都是直接將本地的文件進行了覆蓋,沒有提示信息。

        復制目錄
        [root@virtue ~]# scp -P 22 -r 172.16.20.38:/tmp/script .root@172.16.20.38's password: kernel.txt                                                                             100%   59MB  52.8MB/s   00:01    modify.py                                                                              100%  171   280.1KB/s   00:00    ping.sh                                                                                100%  116   189.0KB/s   00:00    setup.sh                                                                               100%  443   883.6KB/s   00:00    [root@virtue ~]# ll script/總用量 60428-rw-r--r--. 1 root root 61865984 1月  17 14:09 kernel.txt-rw-r--r--. 1 root root      171 1月  17 14:09 modify.py-rw-r--r--. 1 root root      116 1月  17 14:09 ping.sh-rw-r--r--. 1 root root      443 1月  17 14:09 setup.sh

        可以看到目錄也是直接進行了覆蓋,沒有提示信息,所以scp使用的時候一定要確定無誤再使用,否則容易追悔莫及啊~~~



        作者:亦德
        鏈接:https://www.jianshu.com/p/d8ba6c2d4c41
        來源:簡書
        著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。


        *博客內容為網友個人發布,僅代表博主個人觀點,如有侵權請聯系工作人員刪除。

        穩壓二極管相關文章:穩壓二極管的作用


        電荷放大器相關文章:電荷放大器原理


        關鍵詞:

        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 邓州市| 筠连县| 平凉市| 林西县| 色达县| 阜新| 雅安市| 盐源县| 寿光市| 磴口县| 乐至县| 沾益县| 永寿县| 图们市| 寿光市| 长汀县| 开封县| 星子县| 四子王旗| 怀宁县| 秦皇岛市| 格尔木市| 琼结县| 定陶县| 五莲县| 建阳市| 台湾省| 大余县| 梁河县| 舟山市| 仁寿县| 安新县| 隆回县| 三都| 孙吴县| 平顶山市| 马关县| 化隆| 聂拉木县| 衡东县| 会东县|