Search code examples
google-cloud-platformgoogle-compute-enginefile-transferscpcp

Transferring backend files to compute engine from remote workstation


I am following this quickstart for deploying a simple java web app on Compute engine running Debian os. I am facing difficulty in understanding the commands used for transferring files from a remote workstation to compute engine instance. Can someone with example elaborate how to use these

gcloud compute scp --scp-flag=-pr ../../endpoints [INSTANCE-NAME]:~/
  gcloud compute scp ../../pom.xml [INSTANCE-NAME]:~/

commands to transfer web app files from my desktop to compute engine.


Solution

  • To send information from your local machine to a VM:

    $ gcloud compute scp <local-path-to-file> vm:<path-to-dir> --zone <instance-zone>
    

    So for example, if you want to copy a local file named my-local-file in your current directory, to a remote VM named my-vm-1 in zone us-east1-b and put the file inside the folder /home/user-me, you would do:

    gcloud compute scp ./my-local-file my-vm-1:/home/user-me --zone us-east1-b

    You can use the --recurse option for directories as follows:

    gcloud compute scp --recurse ./my-local-file my-vm-1:/home/user-me --zone us-east1-b

    The ssh keys will propagate and the status about the transfer progress is displayed on the terminal window.