What scp
arguments should I use to download a file from an Amazon EC2 instance to local storage?

- 6,214
- 5
- 39
- 53

- 1,745
- 2
- 11
- 6
-
Do you mean on an instance running in the EC2 environment? If so, is it Windows or Linux? Or do you mean a file on S3? – Eric J. Feb 25 '12 at 03:48
-
Did `scp` not work? It does very well for me. – Nishant Feb 25 '12 at 04:00
-
I hava a file generalized from EC2, so it is now in EC2 and wanna transfer it to my computer. The EC2 environment is LINUX. – user1226621 Feb 25 '12 at 04:15
-
[this answer](http://stackoverflow.com/a/9441027/298455) explains how. – Nishant Feb 25 '12 at 05:21
2 Answers
Use scp:
scp -i ec2key.pem username@ec2ip:/remote/path/to/file /local/path/to/file
where:
ec2key.pem
is your PEM keyusername
is the username you log in with into your EC2 instanceec2ip
is the IP or DNS alias of your EC2 instance/remote/path/to/file
is the location where the file is stored on your EC2 instance/local/path/to/file
is where you want to put the file on your local machine
You can use .
to put it into the current folder:
scp -i ec2key.pem username@ec2ip:/remote/path/to/file .
You can read more here on how to access your instance with ssh if you haven't done already:
When you are able to ssh as in the above doc, you will be able to use scp to copy the file.
Another option is to bring up some Web server on your instance, configure HTTPS if your file is sensitive and then download using your browser, here are some tutorials:

- 27,952
- 4
- 66
- 85
-
2Won't this **send** a file TO amazon? What if I want to get the file from there? – gideon Jan 20 '13 at 11:41
-
12@gideon No, it won't. Basic syntax for `scp` is `scp from_file to_file`. In the above, `from_file` is `username@ec2ip:/path/to/file` and `to_file` is `.`, i.e. current folder. To sent to ec2, it would have to be something along the lines: `scp local_file username@ec2ip:/path/on/ec2/machine`. – icyrock.com Jan 20 '13 at 18:39
-
1Ah. Could you help me with this then. When I try it with my ec2 server it doesn't work!! `scp -rp -i mykey.pem ec2-user@mydomain.com:/srv/www/myapp/ .` . It just ends up downloading/copying the folder to my ec2 machine home directory. – gideon Jan 21 '13 at 02:36
-
6@gideon That definitively should work as expected (i.e. recursively copy all files from `/srv/www/myapp/` to the local machine). Wild guess - are you running `scp` from your ec2 server perhaps? If yes, you need to run it from your local machine (i.e. the machine you want to copy files to). – icyrock.com Jan 21 '13 at 05:12
-
shoot! Yes I was silly enough to think it would work like that! :) Thanks a million! – gideon Jan 21 '13 at 06:35
-
12for anyone new here, one easy thing to overlook is the period required at the end of the line. so for it to work you need ..../myapp/ . (with a space between /myapp/ and the period – iliketolearn May 16 '15 at 15:47
-
I cannot find the file on my local machine...Where does this send the file to? – LookIntoEast May 06 '19 at 01:17
-
1If you put a period behind the command, the file will be saved to your home folder, at least on linux – Lucky Jan 17 '20 at 08:26
-
1You have to run this command on your own computer, made the mistake of running it on the command line of the EC2 instance – user12055579 Nov 05 '21 at 17:29
-
If you are using Mac or Linux you can use scp
or even more friendly, download an FTP client, if you are on Mac I recommend you to use CyberDuck. In the end all you need is an FTP client. If you are on Windows I would recommend you Filezilla.
What OS are you in?
Since you are in Ubuntu, try this:
Connect to a file server + In the file manager, click File ▸ Connect to Server.
Enter the server address, select the type of server, and enter any additional information as required. Then click Connect. Details on server types are listed below.
For servers on the internet, you can usually use the domain name. For computers on your local area network, however, you may have to use the computer's numeric IP address. If the other computer is running Ubuntu, see Find your IP address to find that computer's internal IP address. Otherwise, check the help on that computer.
A new window will open showing you the files on the server. Browse the files and folders just as you would for local files and folders.

- 4,140
- 43
- 43

- 3,345
- 1
- 21
- 40
-
My os is a vmware Ubuntu. so I need a FTP client, and could you tell me what to do next? – user1226621 Feb 25 '12 at 04:30
-
1You can probably try this tutorial https://help.ubuntu.com/11.04/ubuntu-help/nautilus-connect.html I have updated my answer with a quote to the site tutorial. – El Developer Feb 25 '12 at 04:45
-
@Dheeraj how can we do that? Sorry for late query.. but I am stuck in a similar situation where I have to download files located at EC2 instance from browser. – Dhruv Singhal Apr 22 '19 at 11:06
-
How can this work with the Ubuntu file manager? If you choose SSH as the server type, it expects a user name and password, which if you configured your server to allow, is a huge security hole. How can you do this using a PEM file? – Robert Oschler May 07 '21 at 21:30