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

时间:2023-01-26 12:51:23

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 scp command to do this?

有人能告诉我正确的scp命令吗?

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

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

6 个解决方案

#1


31  

Call scp from client machine with recursive option:

使用递归选项从客户端计算机调用scp:

scp -r user@remote:src_directory dst_directory

#2


33  

another way to do it is

另一种方法是

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

scp -i“在这里插入密钥文件”-r“在这里插入ec2实例”“你的本地目录”

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

我犯的一个错误是scp -ir。密钥必须在-i之后,而-r之后。

so

所以

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

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

#3


7  

scp -i {key path} -r ec2-user@54.159.147.19:{remote path} {local path}

#4


3  

You could even use rsync.

你甚至可以使用rsync。

rsync -aPSHiv remote:directory .

#5


1  

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

我使用sshfs并将远程目录挂载到本地计算机并执行任何操作。这是一个小指南,命令可能会在您的系统上发生变化

#6


0  

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 z flag to tar to compress on server and uncompress on client.

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

#1


31  

Call scp from client machine with recursive option:

使用递归选项从客户端计算机调用scp:

scp -r user@remote:src_directory dst_directory

#2


33  

another way to do it is

另一种方法是

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

scp -i“在这里插入密钥文件”-r“在这里插入ec2实例”“你的本地目录”

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

我犯的一个错误是scp -ir。密钥必须在-i之后,而-r之后。

so

所以

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

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

#3


7  

scp -i {key path} -r ec2-user@54.159.147.19:{remote path} {local path}

#4


3  

You could even use rsync.

你甚至可以使用rsync。

rsync -aPSHiv remote:directory .

#5


1  

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

我使用sshfs并将远程目录挂载到本地计算机并执行任何操作。这是一个小指南,命令可能会在您的系统上发生变化

#6


0  

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 z flag to tar to compress on server and uncompress on client.

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