如何将整个文件夹从 Amazon EC2 Linux 实例复制到本地 Linux 机器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9330309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:38:37  来源:igfitidea点击:

How to copy entire folder from Amazon EC2 Linux instance to local Linux machine?

linuxsshamazon-ec2sftpscp

提问by Mansoor Elahi

I connected to Amazon's linux instance from ssh using private key. I am trying to copy entire folder from that instance to my local linux machine .

我使用私钥从 ssh 连接到亚马逊的 linux 实例。我正在尝试将整个文件夹从该实例复制到我的本地 linux 机器。

Can anyone tell me the correct scpcommand to do this?

谁能告诉我scp执行此操作的正确命令?

Or do I need something more than scp? Both machines are Ubuntu 10.04 LTS

或者我需要更多的东西scp?两台机器都是 Ubuntu 10.04 LTS

采纳答案by barti_ddu

Call scpfrom client machine with recursive option:

调用scp从客户机递归的选项:

scp -r user@remote:src_directory dst_directory

回答by accfews

I use sshfs and mount remote directory to local machine and do whatever you want. Hereis a small guide, commands may change on your system

我使用 sshfs 并将远程目录挂载到本地机器,然后做任何你想做的事。是一个小指南,您的系统上的命令可能会发生变化

回答by glglgl

You could even use rsync.

你甚至可以使用 rsync。

rsync -aPSHiv remote:directory .

回答by jfg956

I do not like to use scp for large number of files as it does a 'transaction' for each file. The following is much better:

我不喜欢将 scp 用于大量文件,因为它为每个文件执行“事务”。以下要好得多:

cd local_dir; ssh user@server 'cd remote_dir_parent; tar -c remote_dir' | tar -x

You can add a zflag to tar to compress on server and uncompress on client.

您可以z向 tar添加一个标志以在服务器上压缩并在客户端上解压缩。

回答by Raymond Lui

another way to do it is

另一种方法是

scp -i "insert key file here" -r "insert ec2 instance here" "your local directory"

One mistake I made was scp -ir. The key has to be after the -i, and the -rafter that.

我犯的一个错误是scp -ir。关键必须在 之后-i,然后-r是。

so

所以

scp -i amazon.pem -r ec2-user@ec2-##-##-##:/source/dir /destination/dir

回答by Sidharth Srivastava

scp -i {key path} -r [email protected]:{remote path} {local path}

回答by R T

This's how I copied file from amazon ec2 service to local window pc:

这就是我将文件从亚马逊 ec2 服务复制到本地窗口 pc 的方式:

pscp -i "your-key-pair.pem" [email protected]:/home/username/file.txt C:\Documents\

For Linux to copy a directory:

对于 Linux 复制目录:

scp -i "your-key-pair.pem" -r [email protected]:/home/username/dirtocopy /var/www/

To connect to amazon it requires key pair authentication.

要连接到亚马逊,它需要密钥对身份验证。

Note:

笔记:

Username most probably is ubuntu.

用户名很可能是 ubuntu。

回答by Thuvarahan Sivakumar

For EC2 ubuntu

对于 EC2 ubuntu

go to your .pem file directory

转到您的 .pem 文件目录

scp -i "yourkey.pem" -r ec2user@DNS_name:/home/ubuntu/foldername ~/Desktop/localfolder