How To Upload And Download Files In Amazon AWS EC2 Instance

Uploading and downloading files in AWS instance can be done using Filezilla client or Linux scp command. If you are a windows user, you can use WinSCP for transferring files to your EC2 instance.

In this tutorial, I will explain how you can transfer files to AWS instances using the following methods.

  1. Copy Files Using Filezilla Client (GUI Based).
  2. Copy files using SCP (Works only on Linux/MAC systems)

Upload Files To EC2 using FileZilla

You can download FileZilla client from here Download FileZilla.

Step1: Install and open FileZilla

Step2: Go To Edit–>Settings–>SFTP

Click add key file and add your .ppk key of your AWS instance and then click ok. You can convert the AWS pem file to ppk using puttygen. Refer this tutorial –> How To Create .ppk File Using PuttyGen

ec2-upload-download

Step3: In FileZilla homepage enter the host details (public IP, elastic IP or the public DNS) and enter the username in the relevant field. ( username varies for different images. For ubuntu Instance, the username will be ubuntu, for Linux machines, the username will be ec2-user) .

Leave the password field empty, since we are using the private key for authentication.

Port number is 22 for SFTP. Once you enter all the necessary details click connect.

Filezilla will be connected to your server instance and you can view your server files and folders.

sftp-link

Step4: File Upload And Download:- Once FileZilla is connected to your server instance, You can upload files to your instance and also you can download files from your server instance.

The local site is your local system files. The remote site is your server instance.

To upload files choose the directory on your server where you want your files to be uploaded.

Now select the file to be uploaded and right-click on it. Click the upload file option. Your file starts uploading to the directory you selected. Similarly, you can download files from your server instance by right-clicking the file.

Few key things to understand,

  1. Since you are logging in as a user, you cannot upload the files to the root directory due to permissions issues. Alternatively, upload the files to the user home directory and copy it to the desired location using any ssh client like putty.
  2. You will be uploading and downloading files as a normal user and not a root user. So the files which are owned by root cannot be uploaded and downloaded. You will get permission denied error when you try to download a file owned by root.

So, if you want to download those files, ssh into the machine and change the owner of that file to the normal user using the following command.

1sudo chown user:user /folder/file

In the above command, the user is your instance’s default username. For example, for ubuntu instances, it’s ubuntu and for RHEL instances its ec2-user. Give the username accordingly. If you want to change the owner of a recursive folder, add a -R switch to the command, as shown below.

1sudo chown -R user:user /folder/file

Upload File Using SCP Command Line Utility

If you are using a Linux or Mac system, you can use the scp utility to upload files to ec2.

Let’s have a look at the syntax.

1scp -i /path/to/key.pem file-name user@server-ip:/path/to/user/home

For example,

1scp -i /keys/mykey.pem file.txt ubuntu@54.34.45.23:/home/ubuntu

If you want to copy a whole folder, then you should use a recursive flag -r with the command as shown below.

1scp -i /keys/mykey.pem -r folder-name ubuntu@54.34.45.23:/home/ubuntu

I hope this article helps. Let me know in the comments section if you face any errors.

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *

PAGE TOP
error

Enjoy this blog? Please spread the word :)

RSS
Follow by Email