cloud-recipe-image-5

How to Move files in and out of an AWS EC2 Instance – Windows

Background

You can transfer files into and out of a Linux EC2 instance from a local computer running Windows by either of these methods:

  • WinSCP provides a graphical user interface (GUI) that allows you to drag and drop files between your local computer and your AWS instance. This is similar to using Windows File Explorer.
  • PuTTY Secure Copy is run from the Windows Command Prompt

Processing using an EC2 Instance requires that you move the files to be processed to the instance, and then remove the products created before the instance is terminated.

Prerequisites

  • You must have an AWS account. If you don’t have an account, create one now.

Note: You will need to provide credit card information for your new account.

Find Your EC2 Instance Public DNS

  1. Open the AWS Instances window in the EC2 Management Console (1).

The Public DNS of your EC2 instance displayed in this window (2) will be used in the Transferring Files Using WinSCP section and the Transferring Files Using PuTTY Secure Copy (PSCP) section.

The AWS EC2 Management Console.

Transferring Files Using WinSCP

Download and install WinSCP.

    1. Click on Installation package and then use the default installation options.
    2. Start WinSCP by clicking on the Desktop icon.
    3. WinSCP Login window.
      1. Click on New Site (1).
      2. In the Host name box (2), enter the Public DNS displayed in your EC2 Management Console Instances window.
      3. In the User name box (3), type “ubuntu.”
      4. Click on the Advanced button.
    4. Advanced Site Settings window
      1. Under SSH (1), click on Authentication (2)
      2. Under Private key file (3), click on the button and navigate to the folder where your PuTTY Private Key (.ppk) file is located.
        • Select the .ppk file.
      3. Click on the OK button to close the Advanced Site Settings window.

If you want to save your settings to use again later, click on the Save button in the WinSCP Login window and name the settings. 

Note: If you stop your EC2 instance and restart it, a new Public DNS will be assigned. You will need to copy and paste this into the WinSCP “Host name” box before you can connect.

The WinSCP Download page.
The WinSCP Login window.
The Advanced Site Settings window.
    1. Click the Login button
    2. The first time you connect to your instance, you will be asked about connecting to an unknown server.
      1. Click the Yes button to continue.
    3. After you have connected, the left pane of the window will display the file contents of your computer and the right pane displays the contents of your EC2 instance.
    4. Drag and drop files from your computer into your EC2 instance to process. When processing is complete, drag and drop the products from EC2 to your computer.

Important: Files must be transferred from your EC2 instance to your computer before you terminate the instance!

The Login window.
Connect to an Unknown Server window.
EC2 Instance Contents window.

Transferring Files Using PuTTY Secure Copy (PSCP)

Open a Windows “Command Prompt” window

Windows 10

    1. Click on the Start button at the extreme left of the Taskbar.
    2. Scroll down the list of Apps to the Windows System folder.
    3. Expand the folder and click on Command Prompt.
    4. Or, click the Start button and type “cmd.” Select “Command Prompt” from the search results.
    5. The Command Prompt window will open.
The Windows Command Line.
The Windows 10 Taskbar.

Windows 7

    1. Click on the Start button at the left of the Taskbar.
    2. In the Search programs and files box, type “cmd.” Select “Command Prompt” from the search results.
    3. The Command Prompt will open.
The Windows Command Line.
The Windows 7 Taskbar.

Note: When using PSCP to transfer files between your computer and your EC2 instance, your “PuTTY Private Key (.ppk)” file must be in the folder you are working in, or you must provide a path in the PSCP command to the folder the file is located. For example, if “AWSkey.ppk” file is stored in the folder named “keys,” include this path in the PSCP command:

C:\Users\username\keys\AWSkey.ppk

Copy a File Into Your EC2 Instance

At the Windows command prompt type (notice where spaces are placed):

C:\> pscp -i yourkey.ppk yourfilename ubuntu@public_DNS:/home/ubuntu/

Example: To move the file S1A_EW_GRD.zip from your Windows Downloads folder to the /home/ubuntu directory of your EC2 instance.

    1. Use Windows File Explorer to move your awskey.ppk file to your Downloads folder, or provide a path to the folder your.ppk file is located in.
    2. At the Windows command prompt, navigate to your Downloads folder using the change directory (cd) command:

C:\Users\current_user>cd Downloads            and press Enter

    1. At the command prompt, type the PSCP command, which includes your .ppk filename (and path if necessary), the name of the file you want to transfer, the “Public DNS” of your EC2 instance, and the path to a folder in your instance:

C:\> pscp -i awskey.ppk S1A_EW_GRD.zip ubuntu@ec2-52-89-147-172.us-east2.compute.amazonaws.com:/home/ubuntu/

Command syntax (brackets indicate optional paths to your .ppk file and the file you want to move if they are not in the folder you are in):

Windows command prompt — copy a file into your EC2 instance.

C:\> pscp -i C:\<path>\yourkey.ppk C:\<path>\yourfilename ubuntu@public_DNS:/home/ubuntu

Copy a File Out of Your EC2 Instance

At the Windows command prompt type:

C:\> pscp -i yourkey.ppk ubuntu@publicDNS:/home/ubuntu/yourfilename C:\[local_destination_path]\[folder]

Note that the .ppk file must be in the folder you run the command from, or you must include the path to the file in your PSCP command.

If you don’t include a local destination path and folder in the command, the file will download into the folder the command is run from. In this case, the command syntax would be:

C:\> pscp -i C:\[path]\yourkey.ppk ubuntu@publicDNS:/home/ubuntu/[folder]/filename

Example: Move a product generated from an application out of your EC2 instance PRODUCT directory to the Data folder on your Windows computer.

    1. Use Windows File Explorer to move a copy of my awskey.ppk file to your “Data” folder, or provide a path to the folder your.ppk file is located in.
    2. At the Windows command prompt, navigate to your “Data” folder using the change directory (cd) command:

C:\> cd Data           and press ENTER

    1. At the command prompt, type the PSCP command, which includes your .ppk filename, the Public DNS of your EC2 instance, and the name of the file you want to transfer.

C:\> pscp -i awskey.ppk ubuntu@ec2-52-89-147-172.us-east2.compute.amazonaws.com:/home/ubuntu/PRODUCT/F2_unw_phase.tif C:\data_files

Windows command prompt — transfer files.

Command syntax (brackets indicate optional paths to your .ppk file and the file you want to move if they are not in the folder you are in):

C:\> pscp -i C:\[path]\yourkey.ppk ubuntu@public_DNS:/home/ubuntu/[path]/yourfilename C:\[local_destination_path]

Important: Files must be transferred from your EC2 instance to your computer before you terminate the instance!

Comments are closed.