建立外部 SFTP 伺服器

本文說明如何使用 Cloud FTP 建立外部 SFTP 伺服器。外部 SFTP 伺服器可透過網際網路存取。 網路外部的合作夥伴可以使用伺服器,安全地將檔案移轉至 Cloud Storage,或從 Cloud Storage 移轉檔案。

您可以根據使用者的 IP 位址,限制外部安全檔案傳輸通訊協定伺服器的存取權。

如要瞭解如何建立只能在虛擬私有雲 (VPC) 網路中存取的內部伺服器,請參閱「建立內部 SFTP 伺服器」。伺服器建立完成後,就無法變更伺服器是外部還是內部。

事前準備

控制台

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  2. In the Google Cloud console, on the project selector page, select or create 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.

    Go to project selector

  3. 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.

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

  5. 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.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create 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.

    Go to project selector

  7. 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.

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

  9. 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.

    Enable the API

  10. 如要根據使用者的 IP 位址限制伺服器存取權,請收集允許存取伺服器的 CIDR 區塊清單。

gcloud

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  2. 安裝 Google Cloud CLI。

  3. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  4. 執行下列指令,初始化 gcloud CLI:

    gcloud init
  5. 建立或選取 Google Cloud 專案

    選取或建立專案所需的角色

    • 選取專案:選取專案時,不需要具備特定 IAM 角色,只要您在專案中獲派角色,即可選取該專案。
    • 建立專案:如要建立專案,您需要「專案建立者」角色 (roles/resourcemanager.projectCreator),其中包含 resourcemanager.projects.create 權限。瞭解如何授予角色
    • 建立 Google Cloud 專案:

      gcloud projects create PROJECT_ID

      PROJECT_ID 替換為您要建立的 Google Cloud 專案名稱。

    • 選取您建立的 Google Cloud 專案:

      gcloud config set project PROJECT_ID

      PROJECT_ID 替換為 Google Cloud 專案名稱。

  6. 如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。

  7. 確認專案已啟用計費功能 Google Cloud

  8. 啟用 Cloud FTP API:

    啟用 API 時所需的角色

    如要啟用 API,您必須具備 serviceusage.services.enable 權限。如果您建立了專案,可能已透過「擁有者」角色 (roles/owner) 取得這項權限。否則,您可以透過「服務使用情形管理員」角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色

    gcloud services enable ftp.googleapis.com
  9. 安裝 Google Cloud CLI。

  10. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  11. 執行下列指令,初始化 gcloud CLI:

    gcloud init
  12. 建立或選取 Google Cloud 專案

    選取或建立專案所需的角色

    • 選取專案:選取專案時,不需要具備特定 IAM 角色,只要您在專案中獲派角色,即可選取該專案。
    • 建立專案:如要建立專案,您需要「專案建立者」角色 (roles/resourcemanager.projectCreator),其中包含 resourcemanager.projects.create 權限。瞭解如何授予角色
    • 建立 Google Cloud 專案:

      gcloud projects create PROJECT_ID

      PROJECT_ID 替換為您要建立的 Google Cloud 專案名稱。

    • 選取您建立的 Google Cloud 專案:

      gcloud config set project PROJECT_ID

      PROJECT_ID 替換為 Google Cloud 專案名稱。

  13. 如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。

  14. 確認專案已啟用計費功能 Google Cloud

  15. 啟用 Cloud FTP API:

    啟用 API 時所需的角色

    如要啟用 API,您必須具備 serviceusage.services.enable 權限。如果您建立了專案,可能已透過「擁有者」角色 (roles/owner) 取得這項權限。否則,您可以透過「服務使用情形管理員」角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色

    gcloud services enable ftp.googleapis.com
  16. 如要根據使用者的 IP 位址限制伺服器存取權,請收集允許存取伺服器的 CIDR 區塊清單。

必要的角色

如要取得建立 SFTP 伺服器所需的權限,請要求管理員在專案中授予您「Cloud FTP 管理員 」(roles/ftp.admin) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

這個預先定義的角色具備 ftp.servers.create 權限,可建立 SFTP 伺服器。

您或許還可透過自訂角色或其他預先定義的角色取得這項權限。

建立外部伺服器

控制台

  1. 前往 Google Cloud 控制台的「Cloud FTP」頁面。

    前往 Cloud FTP

  2. 按一下「建立伺服器」

  3. 在「伺服器設定」分頁中,輸入伺服器的基本詳細資料:

    1. 在「伺服器 ID」欄位中,輸入伺服器的專屬 ID。

    2. 在「Region」(區域) 清單中,選取伺服器的Google Cloud 位置

      如要以最快的速度傳輸資料,請在儲存資料的 Cloud Storage bucket 所在位置建立伺服器。如果 Cloud FTP 不支援值區位置,請選取最接近的可用位置。

    3. (選用) 輸入伺服器的顯示名稱。

    4. 按一下「繼續」

  4. 在「網路和安全性」分頁中,設定伺服器的連線:

    1. 選取「External (Public IP)」(外部 (公開 IP))

    2. 在「Allowed IP ranges」(允許的 IP 範圍) 欄位中,提供允許存取伺服器的 CIDR 區塊,然後按 Enter 鍵。例如 192.0.2.0/24。您至少須提供一個值,最多可提供 500 個 CIDR 區塊。如要允許來自所有 IP 位址的連線,請使用 0.0.0.0/0

  5. 點選「建立」

    伺服器大約需要 10 分鐘才能建立完成。

gcloud

如要建立外部伺服器,請執行 gcloud alpha storage ftp servers create 指令,並提供 --access-type=EXTERNAL 旗標。

使用下方的任何指令資料之前,請先替換以下項目:

  • SERVER_ID:伺服器的專屬 ID。開頭必須是小寫英文字母,結尾則須為小寫英文字母或數字。可使用小寫英文字母、數字和連字號。 長度上限為 30 個半形字元。
  • LOCATION_ID:伺服器的Google Cloud 位置,例如 us-west1

    如要以最快的速度傳輸資料,請在儲存資料的 Cloud Storage bucket 所在位置建立伺服器。如果 Cloud FTP 不支援值區位置,請選取最接近的可用位置。

  • CIDR_BLOCK:允許存取伺服器的 CIDR 區塊。例如:192.0.2.0/24。您必須至少提供一個值,最多可以提供 500 個 CIDR 區塊,並以逗號分隔的清單提供。如要允許來自所有 IP 位址的連線,請使用 0.0.0.0/0

執行下列指令:

Linux、macOS 或 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

伺服器大約需要 10 分鐘才能建立完成。

REST

如要建立外部伺服器,請使用 servers.create 方法,並提供 externalConfig 存取設定。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:伺服器的 Google Cloud 專案 ID。
  • LOCATION_ID:伺服器的Google Cloud 位置,例如 us-west1

    如要以最快的速度傳輸資料,請在儲存資料的 Cloud Storage bucket 所在位置建立伺服器。如果 Cloud FTP 不支援值區位置,請選取最接近的可用位置。

  • SERVER_ID:伺服器的專屬 ID。開頭必須是小寫英文字母,結尾則須為小寫英文字母或數字。可使用小寫英文字母、數字和連字號。 長度上限為 30 個半形字元。
  • CIDR_BLOCK:允許存取伺服器的 CIDR 區塊。例如:192.0.2.0/24。您至少須提供一個值,最多可提供 500 個 CIDR 區塊。如要允許來自所有 IP 位址的連線,請使用 0.0.0.0/0

HTTP 方法和網址:

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

JSON 要求主體:

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

請展開以下其中一個選項,以傳送要求:

回應會識別長時間執行的作業

伺服器大約需要 10 分鐘才能建立完成。

後續步驟