Directory

如何使用 sftp 獲取目錄及其所有內容?

  • July 10, 2013

當我嘗試使用getsftp 中的命令時,我收到錯誤消息,指出它不是普通文件。有沒有解決的辦法?

sftp -r您可以使用然後使用目錄連接到主機get。如果-r連接時忘記使用,可以使用get -r.

sftp -r me@somehost

要麼

sftp> get -r tmp/
Fetching /home/me/tmp/ to tmp
Retrieving /home/me/tmp
/home/me/new.orig.dmp            100%  417KB 416.8KB/s   00:00    
/home/me/untangle.dmp        100%  398KB 398.3KB/s   00:00    
/home/me/repos.orig.dmp          100%  415KB 415.2KB/s   00:00    
/home/me/me-untangle.dmp 100%   32KB  32.4KB/s   00:00    
sftp>

如果您想始終確保傳遞-rsftp,請將其作為別名添加到您的~/.bashrc或類似的。

alias sftp="sftp -r"

man 1 sftp

-r      Recursively copy entire directories when uploading and download‐
        ing.  Note that sftp does not follow symbolic links encountered
        in the tree traversal.
        .........

get [-Ppr] remote-path [local-path]
        ........
        If either the -P or -p flag is specified, then full file permis‐
        sions and access times are copied too.
        If the -r flag is specified then directories will be copied
        recursively.  Note that sftp does not follow symbolic links when
        performing recursive transfers.

引用自:https://unix.stackexchange.com/questions/39227