shell copy 到远程服务器,shell - 如何使用scp将文件夹从远程复制到本地?

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

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

我使用ssh登录我的服务器。

然后,我想将远程文件夹foo复制到本地/home/user/Desktop。

怎么做到这一点?

11个解决方案

3938 votes

scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/

电话:man scp(查看在线手册)

-r递归复制整个目录

Gryphius answered 2018-12-17T12:12:14Z

242 votes

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

公钥授权

创建ssh别名

然后,例如,如果你有这个〜/ .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-completion,您需要在和主机上安装bash-shell,并正确运行bash-completion。 有关更多信息,请参阅相关问题

如何在使用scp时为远程路径启用自动完成功能?

SCP文件名标签完成

Alexander Yancharuk answered 2018-12-17T12:13:17Z

136 votes

将所有本地位置复制到远程位置(上载)

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

将所有从远程位置复制到本地位置(下载)

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

自定义端口,其中-P portnumber是自定义端口号

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

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

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

救命:

-P portnumber递归复制所有目录和文件

始终使用-P portnumber的完整位置,获取完整的位置pwd

-P portnumber将替换所有现有文件

-P portnumber将是主机名或IP地址

如果需要自定义端口(除了端口22),请使用-P portnumber

。 (点) - 它表示当前工作目录,因此从服务器下载/复制并仅粘贴此处。

注意:由于防火墙中不允许使用端口,有时自定义端口将无法工作,因此请确保防火墙中允许使用自定义端口进行传入和传出连接

Shiv Singh answered 2018-12-17T12:14:37Z

39 votes

我一直用的是:

scp -r username@IP:/path/to/server/source/folder/ .

。 (点):表示125.55.41.311。所以从服务器复制并粘贴到此处。

IP:可以是125.55.41.311等IP地址,也可以是ns1.mysite.com等主机。

Manish Shrivastava answered 2018-12-17T12:15:10Z

24 votes

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

tar czfP backup.tar.gz /path/to/catalog

其次,从远程下载:

scp user@your.server.example.com:/path/to/backup.tar.gz .

最后,解压缩文件:

tar -xzvf backup.tar.gz

justi answered 2018-12-17T12:15:40Z

19 votes

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

这将大大减少文件复制时间。

scp -c blowfish -r user@your.server.example.com:/path/to/foo /home/user/Desktop/

dimuthu answered 2018-12-17T12:16:07Z

14 votes

转到统一工具栏上的文件

ZD6gk.png

按Ctrl + l并写入here_goes_your_user_name@192.168.10.123

192.168.1.103是您要连接的主机。

这里有一个例子

TFZ4B.png

Ronald answered 2018-12-17T12:16:43Z

13 votes

典型情况,

scp -r -P port username@ip:/path-to-folder .

用样品解释,

scp -r -P 27000 abc@10.70.12.12:/tmp/hotel_dump .

哪里,

port = 27000

username = "abc" , remote server username

path-to-folder = tmp/hotel_dump

. = current local directory

Arun G answered 2018-12-17T12:17:19Z

8 votes

如果您遇到“身份验证失败太多”,请指定已添加到服务器ssh服务器的确切SSH密钥:

scp -r -i /path/to/local/key user@remote.tld:/path/to/folder /your/local/target/dir

kaiser answered 2018-12-17T12:17:41Z

7 votes

问题是如何使用Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00命令将文件夹从远程复制到本地。

Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00

但是这是使用Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00的更好方法 - SSH文件传输协议(也称为安全文件传输协议,或SFTP)是一种网络协议,可通过任何可靠的数据流提供文件访问,文件传输和文件管理。(维基百科)。

Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00

Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00

Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00

Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00

有关sftp命令的帮助,请输入help或?。

Fulvio answered 2018-12-17T12:18:25Z

2 votes

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

scp -r . root@888.888.888.888:/usr/share/nginx/www/example.org

Salem F answered 2018-12-17T12:18:46Z

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值