133

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

Anirvan
  • 5,895
  • 5
  • 36
  • 53
user1226621
  • 1,375
  • 2
  • 9
  • 6

2 Answers2

318

Use scp:

scp -i ec2key.pem username@ec2ip:/path/to/file .

where:

  • ec2key.pem is your PEM key
  • username is the username you log in with
  • ec2ip is the IP or DNS alias of the instance
  • /path/to/file is the location where the file is stored

This will copy the file into the current folder on the local machine.

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:

icyrock.com
  • 25,648
  • 4
  • 58
  • 78
  • 2
    Won't this **send** a file TO amazon? What if I want to get the file from there? – gideon Jan 20 '13 at 11:41
  • 10
    @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
  • 1
    Ah. 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
  • 11
    for 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
  • If 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
12

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.

Kirtikumar A.
  • 3,892
  • 40
  • 41
El Developer
  • 3,261
  • 1
  • 18
  • 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
  • 1
    You 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