Introduction
I was recently trying to upload files from my Windows system to a Google Compute Virtual Machine (VM) instance. I thought this guide would help people in the future as details are often scattered or not provided clearly in general tutorials.
This guide serves as assistance for gcloud file transfer from a local computer to a Google instance or vice-versa.
Prerequisites
Before you begin, ensure you have the Google Cloud SDK installed. This provides the necessary command-line tools to interact with your Google Cloud resources.
Step-by-Step Guide
1. Authenticate
Run the Google Cloud SDK Shell. Now authenticate yourself by running the following command:
It will open a URL in your browser & you will be asked to enter your Google account details.
2. Set Project
Once you are authorized, you are required to set the correct project. You can find the correct project ID or project name by clicking on Projects in the Google Developer Console (console.developers.google.com/project).
Here you will get the project ID or name. To set the correct project, run the following command:
3. Prepare for Transfer
After setting the correct project, traverse (cd) to the correct directory on your local machine that contains the files you want to upload/transfer to your Google Virtual Machine.
4. Run the Upload Command
Run the following command to upload the file.
Example:
Troubleshooting Common Errors
You may face some errors during this process. Here are common solutions:
- Error: You do not currently have an active account selected.
Solution: You may have not authenticated yourself correctly. Check step #1 above. - Error: (gcloud.compute.copy-files) The required property [project] is not currently set.
Solution: Step #2 was not done correctly. Ensure you set the project ID. - Error: Unable to fetch a list of zones. Specifying [--zone] may fix this issue. The resource 'projects/' was not found.
Solution: Correct project name was not set. Re-verify the Project ID. - Error: Invalid value. Values must match the following regular expression...
Solution: The path you are giving in the source may not be correct. Check your local directory path. - Error: (gcloud.compute.copy-files) Could not fetch instance.
Solution: You may have missed giving the correct path with the instance name & username (e.g.,user@instance:path). If you believe the command is correct, the problem could be in authentication or project selection (Steps 1 or 2).