Skip to main content

Command Palette

Search for a command to run...

File Transfer between EC2 and another EC2 and Local Machine to EC2

Updated
2 min read
File Transfer between EC2 and another EC2 and Local Machine to EC2

Part 1 : EC2 to Local --> Local to EC2 :

Step 1 : Create an EC2 Instance with any name and with the basic configuration.
Step 2 : Create a normal text file.

cat > text.txt
This is a test file
## Press : CTRL + D
cat text.txt

Step 3 : Now exit the EC2 instance and go to your local system.

##In your Local System type:
scp -i <Your-Key-Pair.pem> ubuntu@<Your-EC2 IP>:/home/ubuntu/text.txt

##This downloads the file in your local system.

Step 4 : Now change the contents in the downloaded text file.
Step 5 : Then log into the ec2 instance via SSH.

scp -i <Your-Key-Pair.pem> text.txt ubuntu@<Your_IP>:/home/ubuntu/

Step 6 : Now you will see that the updated .txt file will be uploaded to the ec2 instance.

Part 2 : EC2 --> EC2 :

Step 1 : Create two ec2 instance with the same key-pair.
Step 2 : In your Local PC run the following command to transfer the Key-Pair to the first ec2 server.

scp -i <Your_Key_Pair.pem> <Your_Key_Pair.pem> ubuntu@<IP_of_EC2_1>:/home/ubuntu/ 

Step 3 : Now SSH into your EC2 1

ssh -i <Your_Key_Pair.pem> ubuntu@<Your_EC2_Public_IP>

Step 4 : Then change the permissions of the Key pair inside the ec2 instance 1.

chmod 400 <Your_Key_Pair.pem>

Step 5 : Now write the code to transfer the file from the first EC2 to second EC2 created.

scp -i <Your_Key_Pair.pem> /home/ubuntu/text.txt ubuntu@<IP_of_EC2_2>:/home/ubuntu/

Step 6 : Now you will see that the .txt file will be transferred to the 2nd EC2 Instance.

Challenges Faced :

  1. Path Confusion (Local vs Remote Paths) : Difficulty in distinguishing between local and remote file paths.

  2. Authentication Errors : Issues related to SSH keys and user credentials.

  3. Network Restrictions / firewalls : Firewalls and security groups blocking required ports.

  4. Lack of clarity on push vs pull model : Confusion about whether the file transfer should be initiated from the source or destination.