如何使用scp将文件夹从远程复制到本地? [关闭]

问题描述 投票:2569回答:11

如何使用scp将文件夹从远程复制到本地主机?

我使用ssh登录我的服务器。然后,我想将远程文件夹foo复制到本地/home/user/Desktop

我该如何实现?

shell command-line copy scp
11个回答
4701
投票
scp -r [email protected]:/path/to/foo /home/user/Desktop/

man scp(请参阅online manual

-r递归复制整个目录


10
投票

问题是如何使用scp命令将文件夹从远程复制到本地。


5
投票

我不知道为什么,但是在源服务器指令之前,我不得不使用本地文件夹。使它工作


298
投票

要使用scp的全部功能,您需要执行以下步骤:

  1. Public key authorisation
  2. Create ssh aliases

然后,例如,如果您有这个〜/ .ssh / config

Host test
    User testuser
    HostName test-site.com
    Port 22022

Host prod
    User produser
    HostName production-site.com
    Port 22022

您将避免输入密码,并简化scp语法,如下所示:

scp -r prod:/path/foo /home/user/Desktop   # copy to local
scp -r prod:/path/foo test:/tmp            # copy from remote prod to remote test

此外,您将可以使用远程路径完成:

scp test:/var/log/  # press tab twice
Display all 151 possibilities? (y or n)

更新:

为了启用远程bash补全,您需要在<source><target>主机上都具有bash-shell,并且bash补全正常工作。有关更多信息,请参见相关问题:

How to enable autocompletion for remote paths when using scp?SCP filename tab completion


199
投票

将全部从本地位置复制到远程位置(上传)

scp -r /path/from/destination username@hostname:/path/to/destination

将全部从远程位置复制到本地位置(下载)

scp -r username@hostname:/path/from/destination /path/to/destination

xxxx自定义端口号的自定义端口

 scp -r -P xxxx username@hostname:/path/from/destination /path/to/destination

远程到本地复制到当前目录

scp -r username@hostname:/path/from/file .

帮助:

  1. [-r递归复制所有目录和文件
  2. 总是使用/中的完整位置,请按pwd中的位置获取完整位置>
  3. [scp将替换所有现有文件
  4. hostname将是主机名或IP地址
  5. 如果需要自定义端口(端口22除外),请使用-P portnumber
  6. 。 (点)
  7. -这表示当前的工作目录,因此只能从服务器下载/复制并粘贴到此处。

    注意:

有时由于防火墙中不允许使用自定义端口,因此请确保在防火墙中允许传入和传出连接使用自定义端口

47
投票

我一直使用的是:


30
投票

最好先在远程服务器上压缩目录:


21
投票

并且,如果您有一个要从远程位置下载的文件,并且您不太在意安全性,请尝试将scp默认加密(Triple-DES)更改为“ blowfish”。


19
投票

转到统一工具栏上的文件


18
投票

典型情况,


12
投票

如果遇到“验证失败太多”

© www.soinside.com 2019 - 2024. All rights reserved.