Transferring Files to Instances

To transfer files to Compute Engine instances, different options are available depending on your workstation OS and the target instance OS.

Transfer from To Linux instances To Windows instances
Linux or macOS
Windows

Transferring files to Linux and Windows instances

You can use Cloud Storage to transfer files across all operating systems.

Transferring files through Cloud Storage

Google Cloud Storage buckets can be a convenient intermediate transfer point between you and your instances, regardless of OS.

This file transfer method works on almost all operating systems and instance types as long as your instance has access to your Cloud Storage bucket through a service account or through your personal user credentials.

Upload your files from your workstation to a Cloud Storage bucket. Then, download those files from the bucket to your instances.

  1. Create a new Cloud Storage bucket or identify an existing bucket that you want to use to transfer files.

  2. From your workstation, upload files to the bucket.

  3. Connect to your instance over SSH or RDP:

  4. On your instance, download files from the bucket.

If you need to transfer files in the other direction, reverse the process. Upload the files from your instance and then download those files to your workstation.

Transferring files to Linux instances

Transferring files using SSH in the browser

If you can establish an SSH connection to an instance using the SSH from the Browser window, you can use that connection to transfer files to the instance.

  1. In the GCP Console, go to the VM Instances page.

    Go to the VM Instances page

  2. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.

    SSH button next to instance name.

  3. After the connection is established, click the gear icon in the top right of the SSH from the Browser window and select Upload File. Alternatively, select Download File to download a file from the instance.
  4. The transfer dialogue window opens. Specify which file you want to transfer.

If you uploaded a file, the file is in your user's /home directory. If you downloaded a file, the file is in the default download folder on your local workstation.

Transferring files using the gcloud command-line tool

The gcloud command-line tool provides an SCP file transfer utility, creating an SSH key pair for you the first time you connect. Your private key is stored on your local device and its corresponding public key is copied to project or instance metadata.

To transfer files using SCP, you must have a firewall rule on the network that your instance uses that allows SSH connections on port 22. Read Using Firewall Rules to learn how to set the necessary firewall rules to allow these connections.

You can install the gcloud tool and use it to copy files and directories to your instance using the scp command.

The following example copies a file from your workstation to the home directory on the instance.

gcloud compute scp [LOCAL_FILE_PATH] [INSTANCE_NAME]:~

where:

  • [LOCAL_FILE_PATH] is the path to the file on your workstation.
  • [INSTANCE_NAME] is the name of your instance.

You can also copy files and directories from an instance to your local workstation. The following example recursively copies a directory from your instance (the source) to your local workstation (the destination).

gcloud compute scp --recurse [INSTANCE_NAME]:[REMOTE_DIR] [LOCAL_DIR]

where:

  • [INSTANCE_NAME] is the name of the instance.
  • [REMOTE_DIR] is the path to the directory on your instance.
  • [LOCAL_DIR] is the path where you want to put the directory on your workstation.

For more information, see the gcloud compute scp reference documentation.

Transferring files using SCP on Linux and macOS workstations

The SCP command-line tool works similarly to the gcloud compute scp, but requires you to manually manage your SSH keys.

To transfer files using SCP, you must have a firewall rule on the network that your instance uses that allows SSH connections on port 22. Read Using Firewall Rules to learn how to set the necessary firewall rules to allow these connections.

The scp tool uses the same key files that you use to connect to your instances using standard SSH.

  1. If you have not yet applied a public key to your GCP Console project or instance, obtain an SSH key pair and apply the public SSH key file to your project or instance.

  2. Find the external IP for the instance that you want to send files to. In a browser, go to the list of your instances.

    Go to the Instances page

  3. Use the scp tool to copy a file from your workstation to the home directory on the target instance. For this example, the private key is at ~/.ssh/my-ssh-key.

    scp -i ~/.ssh/my-ssh-key [LOCAL_FILE_PATH] [USERNAME]@[IP_ADDRESS]:~
    

    where:

    • [USERNAME] is your username.
    • [LOCAL_FILE_PATH] is the name of the local file that you want to upload.
    • [IP_ADDRESS] is the IP address for your instance.

You can also copy files from an instance to your local workstation by reversing the source and destination variables. For this example, copy a file from your instance to a path on your workstation.

scp -i ~/.ssh/my-ssh-key [USERNAME]@[IP_ADDRESS]:[REMOTE_FILE_PATH] [LOCAL_FILE_PATH]

where:

  • [USERNAME] is your username.
  • [REMOTE_FILE_PATH] is the name of the remote file that you want to download.
  • [IP_ADDRESS] is the IP address for your instance.
  • [LOCAL_FILE_PATH] is the location on your workstation where you want to download the file.

Transferring files using WinSCP on Windows workstations

On Windows workstations, the WinSCP client lets you manage files on your instances through a graphical file browser interface.

WinSCP uses the same key files that you use to connect to your instances using PuTTY.

  1. If you have not yet applied a public key to your GCP Console project or instance, obtain an SSH key pair and apply the public SSH key file to your project or instance.

  2. Download and install WinSCP. The default install settings work for most users.

  3. Start the WinSCP program. A login window opens where you can configure your connection settings.

  4. Find the external IP for the instance that you want to send files to. In a browser, go to the list of your instances.

  5. In WinSCP, configure your connection settings.

    1. Set the File protocol field to SCP.

    2. In the Host Name field, specify the external IP address for the instance that you want to connect to.

    3. In the User name field, specify the Google username that you use to access your project. For this example, the user is example-user.

      Setting the file protocol to SCP, the host name to 104.196.31.103, and the user name to example-user.

  6. Click Advanced dropdown menu to open the advanced settings and navigate to SSH > Authentication.

  7. Under the Private key file field, specify the path to your private key file. For this example, the key file is my-ssh-key.ppk.

    Setting the private key file to my-ssh-key.ppk in the Advanced Site Settings.

  8. Click Ok to save the advanced settings.

  9. Click Login to connect to your instance. If the connection is successful, the window opens your local file system on the left and the instance's file system on the right. You can navigate to different directories in these file systems and drag files to transfer them to and from your instance.

  10. You likely do not have permission to manage most files outside of your home directory on the instance. Change directories to the home directory for your user. Enter your home directory to the path field in WinSCP.

    /home/[USERNAME]
    

    where [USERNAME] is your username on that instance.

  11. Use the WinSCP interface to move files between your workstation and the instance.

  12. After you copy your files to the instance, connect to your instance so that you can execute or move files with full sudo permissions.

Transferring files to Windows instances

Transferring files through the Windows RDP client

Desktop RDP clients allow you to connect local devices and resources, including local drives, from your workstation to the Windows Server instance that you connect to. This makes your local workstation file system available as a remote resource while you are connected over RDP. Note that this is not available if you use the GCP Console with the Chrome RDP extension.

For example, on a Windows Server 2016 workstation:

  1. Open RDP.
  2. Click the Local Resources tab.
  3. Under Local devices and resources, click More.
  4. Select the Drives checkbox. When you open a connection to a remote instance, the local drives that you selected are available through Windows Explorer.

For more information, see Microsoft Remote Desktop clients.

What's next

क्या यह पेज उपयोगी था? हमारे काम के बारे में अपनी राय दें:

निम्न के बारे में फ़ीडबैक भेजें...