File and Code Transfer: Local Machine Cloud Server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5175

    #1

    File and Code Transfer: Local Machine Cloud Server

    File and Code Transfer: Local Machine → Cloud Server


    This guide explains four popular methods to transfer files or code from your local computer to a remote cloud server, such as AWS EC2 running Ubuntu.


    1. SCP (Secure Copy Protocol)

    Quickly copy files or folders from your local machine to a remote server over SSH.


    Copy a single file:






    scp -i /path/to/private/key.pem /local/file/path user@SERVER_PUBLIC_IP:/PATH/INSIDE/SERVER







    Copy an entire folder:






    scp -i /path/to/private/key.pem /local/FOLDER/path user@SERVER_PUBLIC_IP:/PATH/INSIDE/SERVER








    2. S3 Method (with IAM Role on EC2)

    Upload files to an S3 bucket from your local machine. Then, grant your EC2 instance permission to access S3, and transfer files directly on the instance.


    Sample IAM Policy for EC2 IAM Role:






    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Effect": "Allow",
    "Action": "s3:*",
    "Resource": [
    "arn:aws:s3:::file-transfer-demo-server-bucket",
    "arn:aws:s3:::file-transfer-demo-server-bucket/*"
    ]
    }
    ]
    }








    Upload from local to S3:






    aws s3 cp /path/to/file s3://file-transfer-demo-server-bucket/








    Download from S3 to EC2:






    aws s3 cp s3://file-transfer-demo-server-bucket/IMG_8366.jpg /home/ubuntu/








    The EC2 instance must have the proper IAM role attached with this policy.


    3. WinSCP or Other SFTP GUI Tools

    For Windows or those who prefer GUIs, use WinSCP (or FileZilla, Cyberduck) for drag-and-drop file transfer:
    • Connect using SFTP, your server’s IP, username (e.g., ubuntu), and your .pem SSH private key.
    • Drag files or folders from local to remote panel.
    • Make sure SFTP/SSH (port 22) is open.


    4. GitHub: Clone Code from Repository

    For code and structured projects, push your content to a GitHub (or GitLab) repository, then on the cloud server:






    git clone https://github.com/yourusername/your-repo.git








    Note:
    • Requires git installed on the cloud server.
    • Best for transferring source code, not large binary files.
    • For all SSH-based methods (SCP, SFTP, WinSCP), ensure the correct username and private key.
    • Always protect your credentials and configure least-privilege access for IAM roles and bucket policies.
    • For large files or many files, S3 or SCP may be more efficient than GitHub.




    More...
Working...