Create an external SFTP server

This document shows how to create an external SFTP server by using Cloud FTP. An external SFTP server can be accessed over the internet. Partners who are outside of your network can use the server to securely transfer files to and from Cloud Storage.

You can restrict access to an external SFTP server based on the IP addresses of your users.

For steps to create an internal server, which can be accessed only within your Virtual Private Cloud (VPC) network, see Create an internal SFTP server. You can't change whether a server is external or internal after the server has been created.

Before you begin

gcloud

  1. Install the Google Cloud CLI.

  2. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  3. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  5. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Cloud FTP API:

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    gcloud services enable ftp.googleapis.com
  8. If you want to restrict access to the server based on your users' IP addresses, collect a list of CIDR blocks that are allowed to access the server.

Required roles

To get the permission that you need to create an SFTP server, ask your administrator to grant you the Cloud FTP Admin (roles/ftp.admin) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the ftp.servers.create permission, which is required to create an SFTP server.

You might also be able to get this permission with custom roles or other predefined roles.

Create an external server

gcloud

To create an external server, run the gcloud alpha storage ftp servers create command and provide the --access-type=EXTERNAL flag.

Before using any of the command data below, make the following replacements:

  • SERVER_ID: a unique ID for the server. Must start with a lowercase letter, and end with a lowercase letter or number. Can contain lowercase letters, numbers, and hyphens. Maximum length is 30 characters.
  • LOCATION_ID: the Google Cloud location of the server, such as us-west1.

    For the fastest data transfer speeds, create the server in the same location as the Cloud Storage bucket that stores your data. If the bucket's location isn't supported by Cloud FTP, then select the nearest available location.

  • CIDR_BLOCK: a CIDR block that is allowed to access the server. For example, 192.0.2.0/24. You must provide at least one value, and can provide a maximum of 500 CIDR blocks in a comma-separated list. To allow connections from all IP addresses, use 0.0.0.0/0.

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud alpha storage ftp servers create SERVER_ID --access-type=EXTERNAL \
    --location=LOCATION_ID --allowed-cidr-blocks=CIDR_BLOCK

Windows (PowerShell)

gcloud alpha storage ftp servers create SERVER_ID --access-type=EXTERNAL `
    --location=LOCATION_ID --allowed-cidr-blocks=CIDR_BLOCK

Windows (cmd.exe)

gcloud alpha storage ftp servers create SERVER_ID --access-type=EXTERNAL ^
    --location=LOCATION_ID --allowed-cidr-blocks=CIDR_BLOCK

It takes about 10 minutes for the server to be created.

REST

To create an external server, use the servers.create method and provide an externalConfig access configuration.

Before using any of the request data, make the following replacements:

  • PROJECT_ID: the Google Cloud project ID of the server.
  • LOCATION_ID: the Google Cloud location of the server, such as us-west1.

    For the fastest data transfer speeds, create the server in the same location as the Cloud Storage bucket that stores your data. If the bucket's location isn't supported by Cloud FTP, then select the nearest available location.

  • SERVER_ID: a unique ID for the server. Must start with a lowercase letter, and end with a lowercase letter or number. Can contain lowercase letters, numbers, and hyphens. Maximum length is 30 characters.
  • CIDR_BLOCK: a CIDR block that is allowed to access the server. For example, 192.0.2.0/24. You must provide at least one value, and can provide a maximum of 500 CIDR blocks . To allow connections from all IP addresses, use 0.0.0.0/0.

HTTP method and URL:

POST https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers?serverId=SERVER_ID

Request JSON body:

{
  "accessType": "EXTERNAL",
  "externalConfig": {
    "allowedCidrBlocks": [
      "CIDR_BLOCK"
      ]
  }
}

To send your request, expand one of these options:

The response identifies a long-running operation.

It takes about 10 minutes for the server to be created.

What's next