Transferring Files to Instances

This guide shows you how to transfer files to either Linux instances or Windows Server instances. The following file transfer methods work on both Linux instances and Windows instances.

Platform-independent transfer methods:

  • Use Google Cloud Storage to transfer files to and from your instances. Cloud Storage buckets can be a convenient intermediate transfer point between you and your instances.

Linux instances:

Windows Server instances:

Before you begin

Platform-independent file transfer methods

If you use Cloud Storage, you can transfer files to your Linux and Windows instances from most Linux, macOS, and Windows workstations.

Transferring files through Cloud Storage

You can use Cloud Storage buckets to transfer files to and from your instances. 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

Some file transfer methods are specific to Linux instances.

Transferring files using the gcloud command-line tool

Use the gcloud tool to copy files to your instance using the copy-files command. The following example copies a file from your workstation to the home directory on the instance.

gcloud compute copy-files [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 from an instance to your local workstation by reversing the source and destination variables. The following example copies a file from your instance to your workstation.

gcloud compute copy-files [INSTANCE_NAME]:[REMOTE_FILE_PATH] [LOCAL_FILE_PATH]

where:

  • [INSTANCE_NAME] is the name of the instance.
  • [REMOTE_FILE_PATH] is the path to the file on your instance.
  • [LOCAL_FILE_PATH] is the path where you want to put the file on your workstation.

Transferring files using the file browser on Linux or macOS workstations

On Linux or macOS workstations, you can use your native file browser to transfer files to your instances. If you need to transfer files using the command line, use the scp command. To transfer files using your file browser:

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

  2. Open a terminal and add an entry in your ~/.ssh/config file that points to your private key. For this example, the private key file is ~/.ssh/my-ssh-key.

    echo "IdentityFile ~/.ssh/my-ssh-key" >> ~/.ssh/config
    
  3. Open your file browser and establish a connection to your instance. Paste the combined username and IP address into your file browser:

    Opening a file browser and pasting sftp://example-user@104.196.31.103 to the file path.

  4. 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. In the file browser, add the path to your home directory to the end of the instance URL:

    sftp://[USERNAME]@[IP_ADDRESS]/home/[USERNAME]
    

    where:

    • [USERNAME] is your username on that instance.
    • [IP_ADDRESS] is the IP address for your instance.
  5. Use your file browser to copy files to your instance.

  6. 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 using SCP on Linux and macOS workstations

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 Cloud Platform 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

WinSCP uses the same key files that you use to connect to your instances using PuTTY. Use WinSCP to transfer files between your Windows workstation and your instance.

  1. If you have not yet applied a public key to your Cloud Platform 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 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 Server instances

Some file transfer methods are specific to Windows instances.

Transferring files through the Windows RDP client

Some RDP clients allow you to mount directories from your workstation to the Windows Server instance that you connect to. This makes your workstation file system available on the instance while you are connected over RDP.

Use the Microsoft Remote Desktop client to transfer files to your instances.

What's next

Send feedback about...

Compute Engine Documentation