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

发布于 2025-01-06 23:46:57 字数 182 浏览 6 评论 0原文

我使用私钥从 ssh 连接到 Amazon 的 linux 实例。我正在尝试将整个文件夹从该实例复制到我的本地 Linux 计算机。

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

或者我还需要 scp 以外的东西吗? 两台机器都是 Ubuntu 10.04 LTS

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 .

Can anyone tell me the correct scp command to do this?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

安稳善良 2025-01-13 23:46:57

另一种方法是

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

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

所以

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

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 -r after that.

so

scp -i amazon.pem -r ec2-user@ec2-##-##-##:/source/dir /destination/dir
入怼 2025-01-13 23:46:57

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

scp -r user@remote:src_directory dst_directory

Call scp from client machine with recursive option:

scp -r user@remote:src_directory dst_directory
指尖上得阳光 2025-01-13 23:46:57
scp -i {key path} -r [email protected]:{remote path} {local path}
scp -i {key path} -r [email protected]:{remote path} {local path}
北城挽邺 2025-01-13 23:46:57

对于 EC2 ubuntu,

请转到您的 .pem 文件目录

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

For EC2 ubuntu

go to your .pem file directory

scp -i "yourkey.pem" -r ec2user@DNS_name:/home/ubuntu/foldername ~/Desktop/localfolder
乖乖哒 2025-01-13 23:46:57

您甚至可以使用 rsync。

rsync -aPSHiv remote:directory .

You could even use rsync.

rsync -aPSHiv remote:directory .
唠甜嗑 2025-01-13 23:46:57

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

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

对于 Linux 复制目录:

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

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

注意:

用户名很可能是 ubuntu。

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

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

For Linux to copy a directory:

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.

梦中的蝴蝶 2025-01-13 23:46:57

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

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

ぃ弥猫深巷。 2025-01-13 23:46:57

这也很重要,并且与上面的答案相关。
将本地目录中的所有文件复制到 EC2。这是 Unix 的答案。

将整个本地文件夹复制到 EC2 中的文件夹:
scp -i "key-pair.pem" -r /home/Projects/myfiles [电子邮件受保护]:/home/dir

仅将本地文件夹的全部内容复制到 EC2 中的文件夹:
scp -i "key-pair.pem" -r /home/Projects/myfiles/* [电子邮件受保护]:/home/dir

This is also important and related to the above answer.
Copying all files in a local directory to EC2. This is a Unix answer.

Copy the entire local folder to a folder in EC2:
scp -i "key-pair.pem" -r /home/Projects/myfiles [email protected]:/home/dir

Copy only the entire contents of local folder to folder in EC2:
scp -i "key-pair.pem" -r /home/Projects/myfiles/* [email protected]:/home/dir

辞慾 2025-01-13 23:46:57

我不喜欢对大量文件使用 scp,因为它为每个文件执行“事务”。下面的方法要好得多:

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

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

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:

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.

因为看清所以看轻 2025-01-13 23:46:57

我在 youtube 上发现的一种方法是将本地文件夹与 EC2 实例中的共享文件夹连接。请观看此视频了解完整说明。共享是即时的。

One way I found on youtube is to connect a local folder with a shared folder in EC2 instance. Please view this video for the full instruction. The sharing is instantaneous.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文