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.

Download: First of all, download the Google Cloud SDK Shell. You can download it from the following link: Google Cloud SDK Download.

Step-by-Step Guide

1. Authenticate

Run the Google Cloud SDK Shell. Now authenticate yourself by running the following command:

gcloud auth login

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:

gcloud config set project PROJECTNAME

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.

gcloud compute copy-files [Source directory or file name] [destination directory of file name]

Example:

# Source: 'test' folder in current directory # Destination: /var/www/ on the remote instance gcloud compute copy-files test test_gmail_com@YOURINSTANCENAME:/var/www/

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).
Ucodice Team

The Ucodice Team is a group of passionate developers, designers, and strategists dedicated to delivering top-tier IT solutions to clients worldwide.