如何使用 sftp 获取目录及其所有内容?

Pau*_*aul 6 scp sftp directory

当我尝试使用get来自 sftp的命令时,我收到错误消息,指出它不是一个普通文件。有没有解决的办法?

Geo*_*e M 18

您可以使用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>
Run Code Online (Sandbox Code Playgroud)

如果您想始终确保您传递-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.
Run Code Online (Sandbox Code Playgroud)

  • 为什么我的 sftp 客户端没有 -r 选项?>>>>>sftp: 非法选项 -- r (2认同)