Membuat server SFTP internal

Dokumen ini menunjukkan cara membuat server SFTP internal menggunakan Cloud FTP. Server SFTP internal hanya dapat diakses dalam jaringan Virtual Private Cloud (VPC) Anda menggunakan Private Service Connect. Karyawan dan pemangku kepentingan internal yang berada dalam jaringan Anda dapat menggunakan server untuk mentransfer file dengan aman ke dan dari Cloud Storage.

Anda menentukan project yang diizinkan untuk terhubung ke server. Anda dapat menentukan project yang ditolak untuk terhubung, jika perlu.

Untuk mengetahui informasi latar belakang tentang VPC, lihat Ringkasan VPC.

Untuk mengetahui langkah-langkah membuat server eksternal, yang dapat diakses melalui internet, lihat Membuat server SFTP eksternal. Anda tidak dapat mengubah apakah server bersifat eksternal atau internal setelah server dibuat.

Sebelum memulai

Konsol

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  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, if it is not already enabled.

    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, if it is not already enabled.

    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. Kumpulkan informasi berikut tentang pengguna server Anda:

    • Daftar project ID atau nomor project yang diizinkan untuk mengakses server.
    • (Opsional) Daftar project ID atau nomor project yang ditolak untuk mengakses server.

gcloud

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  2. Instal Google Cloud CLI.

  3. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  4. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  5. Buat atau pilih project Google Cloud .

    Peran yang diperlukan untuk memilih atau membuat project

    • Memilih project: Memilih project tidak memerlukan peran IAM tertentu—Anda dapat memilih project apa pun yang perannya telah diberikan kepada Anda.
    • Membuat project: Untuk membuat project, Anda memerlukan peran Project Creator (roles/resourcemanager.projectCreator), yang berisi izin resourcemanager.projects.create. Pelajari cara memberikan peran.
    • Buat project Google Cloud :

      gcloud projects create PROJECT_ID

      Ganti PROJECT_ID dengan nama untuk Google Cloud project yang Anda buat.

    • Pilih project Google Cloud yang Anda buat:

      gcloud config set project PROJECT_ID

      Ganti PROJECT_ID dengan nama project Google Cloud Anda.

  6. Jika Anda menggunakan project yang sudah ada untuk panduan ini, pastikan Anda memiliki izin yang diperlukan untuk menyelesaikan panduan ini. Jika berhasil membuat project baru, berarti Anda sudah memiliki izin yang diperlukan.

  7. Pastikan penagihan diaktifkan untuk project Google Cloud Anda.

  8. Aktifkan Cloud FTP API, jika belum diaktifkan:

    Peran yang diperlukan untuk mengaktifkan API

    Untuk mengaktifkan API, Anda memerlukan izin serviceusage.services.enable. Jika Anda membuat project, kemungkinan Anda sudah memiliki izin ini melalui peran Pemilik (roles/owner). Jika tidak, Anda bisa mendapatkan izin ini melalui peran Service Usage Admin (roles/serviceusage.serviceUsageAdmin). Pelajari cara memberikan peran.

    gcloud services enable ftp.googleapis.com
  9. Instal Google Cloud CLI.

  10. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  11. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  12. Buat atau pilih project Google Cloud .

    Peran yang diperlukan untuk memilih atau membuat project

    • Memilih project: Memilih project tidak memerlukan peran IAM tertentu—Anda dapat memilih project apa pun yang perannya telah diberikan kepada Anda.
    • Membuat project: Untuk membuat project, Anda memerlukan peran Project Creator (roles/resourcemanager.projectCreator), yang berisi izin resourcemanager.projects.create. Pelajari cara memberikan peran.
    • Buat project Google Cloud :

      gcloud projects create PROJECT_ID

      Ganti PROJECT_ID dengan nama untuk Google Cloud project yang Anda buat.

    • Pilih project Google Cloud yang Anda buat:

      gcloud config set project PROJECT_ID

      Ganti PROJECT_ID dengan nama project Google Cloud Anda.

  13. Jika Anda menggunakan project yang sudah ada untuk panduan ini, pastikan Anda memiliki izin yang diperlukan untuk menyelesaikan panduan ini. Jika berhasil membuat project baru, berarti Anda sudah memiliki izin yang diperlukan.

  14. Pastikan penagihan diaktifkan untuk project Google Cloud Anda.

  15. Aktifkan Cloud FTP API, jika belum diaktifkan:

    Peran yang diperlukan untuk mengaktifkan API

    Untuk mengaktifkan API, Anda memerlukan izin serviceusage.services.enable. Jika Anda membuat project, kemungkinan Anda sudah memiliki izin ini melalui peran Pemilik (roles/owner). Jika tidak, Anda bisa mendapatkan izin ini melalui peran Service Usage Admin (roles/serviceusage.serviceUsageAdmin). Pelajari cara memberikan peran.

    gcloud services enable ftp.googleapis.com
  16. Kumpulkan informasi berikut tentang pengguna server Anda:

    • Daftar project ID atau nomor project yang diizinkan untuk mengakses server.
    • (Opsional) Daftar project ID atau nomor project yang ditolak untuk mengakses server.

Peran yang diperlukan

Untuk mendapatkan izin yang diperlukan guna membuat server SFTP, minta administrator untuk memberi Anda peran IAM Cloud FTP Admin (roles/ftp.admin) di project Anda. Untuk mengetahui informasi selengkapnya tentang cara memberikan peran, lihat Mengelola akses ke project, folder, dan organisasi.

Peran bawaan ini berisi izin yang diperlukan untuk membuat server SFTP. Untuk melihat izin yang benar-benar diperlukan, perluas bagian Izin yang diperlukan:

Izin yang diperlukan

Izin berikut diperlukan untuk membuat server SFTP:

  • ftp.servers.create
  • Jika menggunakan konsol Google Cloud untuk melakukan tugas ini:
    • ftp.servers.list
    • ftp.locations.list

Anda mungkin juga bisa mendapatkan izin ini dengan peran khusus atau peran bawaan lainnya.

Membuat server internal

Konsol

  1. Di konsol Google Cloud , buka halaman Cloud FTP.

    Buka Cloud FTP

  2. Klik Create server.

  3. Di tab Server configuration, masukkan detail dasar untuk server:

    1. Di kolom Server ID, masukkan ID unik untuk server.

    2. Dalam daftar Region, pilih Google Cloud lokasi untuk server.

      Untuk kecepatan transfer data tercepat, buat server di lokasi yang sama dengan bucket Cloud Storage yang menyimpan data Anda. Jika lokasi bucket tidak didukung oleh Cloud FTP, pilih lokasi terdekat yang tersedia.

    3. (Opsional) Masukkan nama tampilan untuk server.

    4. Klik Lanjutkan.

  4. Di tab Networking and security, konfigurasikan konektivitas untuk server:

    1. Pilih Internal (VPC only).

    2. Di bagian Accepted projects, tentukan project konsumen yang diizinkan untuk terhubung ke server menggunakan Private Service Connect. Lakukan tindakan berikut:

      1. Di kolom Project ID or number, masukkan project ID atau nomor project yang diizinkan untuk terhubung. Contoh, example-allowed-project.

      2. Di kolom Connection limit, masukkan jumlah maksimum endpoint Private Service Connect yang dapat dibuat di project konsumen. Nilai harus antara 1 hingga 250 endpoint.

      3. Untuk menambahkan lebih banyak project, klik Add accepted project, lalu ulangi langkah-langkah sebelumnya.

    3. (Opsional) Untuk melarang project terhubung ke server, di bagian Rejected projects, klik Add rejected project. Masukkan project ID atau nomor project konsumen yang dilarang terhubung ke server.

      Project dalam daftar ini ditolak untuk mengakses server meskipun project tersebut disertakan dalam daftar project yang diizinkan.

  5. Klik Create.

    Perlu waktu sekitar 10 menit untuk membuat server.

gcloud

Untuk membuat server internal, jalankan perintah gcloud alpha storage ftp servers create dan berikan flag --access-type=INTERNAL.

Sebelum menggunakan salah satu data perintah di bawah, lakukan penggantian berikut:

  • SERVER_ID: ID unik untuk server. Harus diawali dengan huruf kecil, dan diakhiri dengan huruf kecil atau angka. Dapat berisi huruf kecil, angka, dan tanda hubung. Tidak boleh diawali dengan awalan goog atau berisi string google, termasuk kesalahan ejaan yang mirip seperti g00gle. Panjang maksimum adalah 30 karakter.
  • LOCATION_ID: Google Cloud lokasi server, seperti us-west1.

    Untuk kecepatan transfer data tercepat, buat server di lokasi yang sama dengan bucket Cloud Storage yang menyimpan data Anda. Jika lokasi bucket tidak didukung oleh Cloud FTP, pilih lokasi terdekat yang tersedia.

  • PROJECT_TO_ALLOW: project ID atau nomor project konsumen yang diizinkan untuk terhubung ke server menggunakan Private Service Connect. Misalnya, example-allowed-project. Anda harus menentukan setidaknya satu project.

    Anda dapat mengizinkan maksimum 500 project. Berikan beberapa project dan batas koneksi masing-masing dalam daftar yang dipisahkan koma. Misalnya, --consumer-accept-list=projectA=20,projectB=15.

  • CONNECTION_LIMIT: jumlah maksimum endpoint Private Service Connect yang dapat dibuat di project konsumen. Nilai harus antara 1 hingga 250 endpoint.
  • (Opsional) PROJECT_TO_REJECT: project ID atau nomor project konsumen yang dilarang terhubung ke server. Contoh, example-rejected-project. Project dalam daftar ini ditolak untuk mengakses server meskipun disertakan dalam daftar project yang diizinkan.

    Anda dapat menolak maksimum 64 project. Berikan beberapa project dalam daftar yang dipisahkan koma.

    Jika Anda tidak ingin menolak project apa pun secara eksplisit, hapus flag --consumer-reject-list.

Jalankan perintah berikut:

Linux, macOS, atau Cloud Shell

gcloud alpha storage ftp servers create SERVER_ID --access-type=INTERNAL \
    --location=LOCATION_ID \
    --consumer-accept-list=PROJECT_TO_ALLOW=CONNECTION_LIMIT \
    --consumer-reject-list=PROJECT_TO_REJECT

Windows (PowerShell)

gcloud alpha storage ftp servers create SERVER_ID --access-type=INTERNAL `
    --location=LOCATION_ID `
    --consumer-accept-list=PROJECT_TO_ALLOW=CONNECTION_LIMIT `
    --consumer-reject-list=PROJECT_TO_REJECT

Windows (cmd.exe)

gcloud alpha storage ftp servers create SERVER_ID --access-type=INTERNAL ^
    --location=LOCATION_ID ^
    --consumer-accept-list=PROJECT_TO_ALLOW=CONNECTION_LIMIT ^
    --consumer-reject-list=PROJECT_TO_REJECT

Perlu waktu sekitar 10 menit untuk membuat server.

REST

Untuk membuat server internal, gunakan metode servers.create dan berikan konfigurasi akses internalConfig.

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • PROJECT_ID: project ID Google Cloud server.
  • LOCATION_ID: Google Cloud lokasi server, seperti us-west1.

    Untuk kecepatan transfer data tercepat, buat server di lokasi yang sama dengan bucket Cloud Storage yang menyimpan data Anda. Jika lokasi bucket tidak didukung oleh Cloud FTP, pilih lokasi terdekat yang tersedia.

  • SERVER_ID: ID unik untuk server. Harus diawali dengan huruf kecil, dan diakhiri dengan huruf kecil atau angka. Dapat berisi huruf kecil, angka, dan tanda hubung. Tidak boleh diawali dengan awalan goog atau berisi string google, termasuk kesalahan ejaan yang mirip seperti g00gle. Panjang maksimum adalah 30 karakter.
  • PROJECT_TO_ALLOW: project ID atau nomor project konsumen yang diizinkan untuk terhubung ke server menggunakan Private Service Connect. Misalnya, example-allowed-project. Anda harus menentukan setidaknya satu project.

    Anda dapat mengizinkan maksimum 500 project.

  • CONNECTION_LIMIT: jumlah maksimum endpoint Private Service Connect yang dapat dibuat di project konsumen. Nilai harus antara 1 hingga 250 endpoint.
  • (Opsional) PROJECT_TO_REJECT: project ID atau nomor project konsumen yang dilarang terhubung ke server. Contoh, example-rejected-project. Project dalam daftar ini ditolak untuk mengakses server meskipun disertakan dalam daftar project yang diizinkan.

    Anda dapat menolak maksimum 64 project.

    Jika Anda tidak ingin menolak project apa pun secara eksplisit, hapus objek consumerRejectList.

Metode HTTP dan URL:

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

Meminta isi JSON:

{
  "accessType": "INTERNAL",
  "internalConfig": {
    "consumerAcceptList": [
      {
        "project": "projects/PROJECT_TO_ALLOW",
        "connectionLimit": CONNECTION_LIMIT
      }
    ],
    "consumerRejectList": [
      {
        "project": "projects/PROJECT_TO_REJECT"
      }
    ]
  }
}

Untuk mengirim permintaan Anda, perluas salah satu opsi berikut:

Respons mengidentifikasi operasi yang berjalan lama.

Perlu waktu sekitar 10 menit untuk membuat server.

Library klien

Untuk membuat server internal, tetapkan jenis akses ke internal dan berikan konfigurasi akses internal.

C#

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API C# Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

using Google.Cloud.Ftp.V1;
using Google.LongRunning;
using System.Threading.Tasks;

public sealed partial class GeneratedCloudFtpClientSnippets
{
    /// <summary>Snippet for CreateServerAsync</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public async Task CreateServerAsync()
    {
        // Create client
        CloudFtpClient cloudFtpClient = await CloudFtpClient.CreateAsync();
        // Initialize request argument(s)
        string parent = "projects/[PROJECT]/locations/[LOCATION]";
        Server server = new Server();
        string serverId = "";
        // Make the request
        Operation<Server, OperationMetadata> response = await cloudFtpClient.CreateServerAsync(parent, server, serverId);

        // Poll until the returned long-running operation is complete
        Operation<Server, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();
        // Retrieve the operation result
        Server result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Server, OperationMetadata> retrievedResponse = await cloudFtpClient.PollOnceCreateServerAsync(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Server retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Go Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


//go:build examples

package main

import (
	"context"

	ftp "cloud.google.com/go/ftp/apiv1"
	ftppb "cloud.google.com/go/ftp/apiv1/ftppb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := ftp.NewCloudFtpRESTClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &ftppb.CreateServerRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/ftp/apiv1/ftppb#CreateServerRequest.
	}
	op, err := c.CreateServer(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Java Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import com.google.api.core.ApiFuture;
import com.google.cloud.ftp.v1.CloudFtpClient;
import com.google.cloud.ftp.v1.CreateServerRequest;
import com.google.cloud.ftp.v1.LocationName;
import com.google.cloud.ftp.v1.Server;
import com.google.longrunning.Operation;

public class AsyncCreateServer {

  public static void main(String[] args) throws Exception {
    asyncCreateServer();
  }

  public static void asyncCreateServer() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CloudFtpClient cloudFtpClient = CloudFtpClient.create()) {
      CreateServerRequest request =
          CreateServerRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setServerId("serverId1379103678")
              .setServer(Server.newBuilder().build())
              .setRequestId("requestId693933066")
              .build();
      ApiFuture<Operation> future = cloudFtpClient.createServerCallable().futureCall(request);
      // Do something.
      Operation response = future.get();
    }
  }
}

Node.js

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Node.js Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Value for parent.
 */
// const parent = 'abc123'
/**
 *  Required. 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.
 */
// const serverId = 'abc123'
/**
 *  Required. The resource being created
 */
// const server = {}
/**
 *  Optional. An optional request ID to identify requests. Specify a unique
 *  request ID so that if you must retry your request, the server will know to
 *  ignore the request if it has already been completed. The server will
 *  guarantee that for at least 60 minutes since the first request.
 *  For example, consider a situation where you make an initial request and the
 *  request times out. If you make the request again with the same request
 *  ID, the server can check if original operation with the same request ID
 *  was received, and if so, will ignore the second request. This prevents
 *  clients from accidentally creating duplicate commitments.
 *  The request ID must be a valid UUID with the exception that zero UUID is
 *  not supported (00000000-0000-0000-0000-000000000000).
 */
// const requestId = 'abc123'

// Imports the Ftp library
const {CloudFtpClient} = require('@google-cloud/ftp').v1;

// Instantiates a client
const ftpClient = new CloudFtpClient();

async function callCreateServer() {
  // Construct request
  const request = {
    parent,
    serverId,
    server,
  };

  // Run request
  const [operation] = await ftpClient.createServer(request);
  const [response] = await operation.promise();
  console.log(response);
}

callCreateServer();

PHP

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API PHP Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Ftp\V1\Client\CloudFtpClient;
use Google\Cloud\Ftp\V1\CreateServerRequest;
use Google\Cloud\Ftp\V1\Server;
use Google\Cloud\Ftp\V1\Server\AccessType;
use Google\Rpc\Status;

/**
 * Creates a new Server in a given project and location.
 *
 * @param string $formattedParent  Value for parent. Please see
 *                                 {@see CloudFtpClient::locationName()} for help formatting this field.
 * @param string $serverId         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.
 * @param int    $serverAccessType The access type of the Server.
 */
function create_server_sample(
    string $formattedParent,
    string $serverId,
    int $serverAccessType
): void {
    // Create a client.
    $cloudFtpClient = new CloudFtpClient();

    // Prepare the request message.
    $server = (new Server())
        ->setAccessType($serverAccessType);
    $request = (new CreateServerRequest())
        ->setParent($formattedParent)
        ->setServerId($serverId)
        ->setServer($server);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudFtpClient->createServer($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Server $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CloudFtpClient::locationName('[PROJECT]', '[LOCATION]');
    $serverId = '[SERVER_ID]';
    $serverAccessType = AccessType::ACCESS_TYPE_UNSPECIFIED;

    create_server_sample($formattedParent, $serverId, $serverAccessType);
}

Python

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Python Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import ftp_v1


def sample_create_server():
    # Create a client
    client = ftp_v1.CloudFtpClient()

    # Initialize request argument(s)
    server = ftp_v1.Server()
    server.access_type = "INTERNAL"

    request = ftp_v1.CreateServerRequest(
        parent="parent_value",
        server_id="server_id_value",
        server=server,
    )

    # Make the request
    operation = client.create_server(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud FTP, lihat Library klien Cloud FTP. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Ruby Cloud FTP.

Untuk melakukan autentikasi ke Cloud FTP, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

require "google/cloud/ftp/v1"

##
# Snippet for the create_server call in the CloudFtp service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Ftp::V1::CloudFtp::Rest::Client#create_server.
#
def create_server
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Ftp::V1::CloudFtp::Rest::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Ftp::V1::CreateServerRequest.new

  # Call the create_server method.
  result = client.create_server request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

Langkah berikutnya