SFTP サーバーを更新する

Cloud FTP サーバーに接続できるユーザーを更新するには、サーバーのアクセス構成を更新します。サーバーの表示名などのメタデータを更新することもできます。

サーバーの作成後に、サーバーが外部か内部かを変更することはできません。

必要なロール

SFTP サーバーの更新に必要な権限を取得するには、プロジェクトに対する Cloud FTP 管理者 (roles/ftp.admin)IAM ロールを付与するよう管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織に対するアクセス権の管理をご覧ください。

この事前定義ロールには、SFTP サーバーを更新するために必要な ftp.servers.update 権限が含まれています。

カスタムロールや他の事前定義ロールを使用して、この権限を取得することもできます。

外部サーバーのアクセス権を更新する

gcloud

外部サーバーのアクセス構成を更新するには、gcloud alpha storage ftp servers update コマンドを実行します。--allowed-cidr-blocks フラグを指定します。

後述のコマンドデータを使用する前に、次のように置き換えます。

  • SERVER_ID: サーバー ID。
  • LOCATION_ID: サーバーのロケーション(us-west1 など)。
  • CIDR_BLOCK: サーバーへのアクセスが許可されている CIDR ブロック。例: 192.0.2.0/24少なくとも 1 つの値を指定する必要があります。カンマ区切りのリストで最大 500 個の CIDR ブロックを指定できます。すべての IP アドレスからの接続を許可するには、0.0.0.0/0 を使用します。

次のコマンドを実行します。

Linux、macOS、Cloud Shell

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID \
    --allowed-cidr-blocks=CIDR_BLOCK

Windows(PowerShell)

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID `
    --allowed-cidr-blocks=CIDR_BLOCK

Windows(cmd.exe)

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID ^
    --allowed-cidr-blocks=CIDR_BLOCK
サーバーの更新には数秒かかります。

REST

外部サーバーのアクセス構成を更新するには、servers.patch メソッドを使用します。updateMask クエリ パラメータに externalConfig フィールドを指定します。

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: サーバーの Google Cloud プロジェクト ID。
  • LOCATION_ID: サーバーのロケーション(us-west1 など)。
  • SERVER_ID: サーバー ID。
  • CIDR_BLOCK: サーバーへのアクセスが許可されている CIDR ブロック。例: 192.0.2.0/24少なくとも 1 つの値を指定する必要があります。最大 500 個の CIDR ブロックを指定できます。すべての IP アドレスからの接続を許可するには、0.0.0.0/0 を使用します。

HTTP メソッドと URL:

PATCH https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID?updateMask=externalConfig

リクエストの本文(JSON):

{
  "externalConfig": {
    "allowedCidrBlocks": [
      "CIDR_BLOCK"
    ]
  }
}

リクエストを送信するには、次のいずれかのオプションを展開します。

レスポンスで長時間実行オペレーションを識別できます。サーバーの更新には数秒かかります。 <0

クライアント ライブラリ

C#

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP C# API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

public sealed partial class GeneratedCloudFtpClientSnippets
{
    /// <summary>Snippet for UpdateServerAsync</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 UpdateServerAsync()
    {
        // Create client
        CloudFtpClient cloudFtpClient = await CloudFtpClient.CreateAsync();
        // Initialize request argument(s)
        Server server = new Server();
        FieldMask updateMask = new FieldMask();
        // Make the request
        Operation<Server, OperationMetadata> response = await cloudFtpClient.UpdateServerAsync(server, updateMask);

        // 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.PollOnceUpdateServerAsync(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

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP Go API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


//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.UpdateServerRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/ftp/apiv1/ftppb#UpdateServerRequest.
	}
	op, err := c.UpdateServer(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

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

Java

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP Java API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.api.core.ApiFuture;
import com.google.cloud.ftp.v1.CloudFtpClient;
import com.google.cloud.ftp.v1.Server;
import com.google.cloud.ftp.v1.UpdateServerRequest;
import com.google.longrunning.Operation;
import com.google.protobuf.FieldMask;

public class AsyncUpdateServer {

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

  public static void asyncUpdateServer() 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()) {
      UpdateServerRequest request =
          UpdateServerRequest.newBuilder()
              .setUpdateMask(FieldMask.newBuilder().build())
              .setServer(Server.newBuilder().build())
              .setRequestId("requestId693933066")
              .build();
      ApiFuture<Operation> future = cloudFtpClient.updateServerCallable().futureCall(request);
      // Do something.
      Operation response = future.get();
    }
  }
}

Node.js

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP Node.js API リファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * 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.
 */
/**
 *  Optional. Field mask is used to specify the fields to be overwritten in the
 *  Server resource by the update.
 *  The fields specified in the update_mask are relative to the resource, not
 *  the full request. A field will be overwritten if it is in the mask. If the
 *  user does not provide a mask then all fields present in the request will be
 *  overwritten.
 */
// const updateMask = {}
/**
 *  Required. The resource being updated
 */
// 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 callUpdateServer() {
  // Construct request
  const request = {
    server,
  };

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

callUpdateServer();

PHP

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP PHP API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

/**
 * Updates the parameters of a single Server.
 *
 * @param int $serverAccessType The access type of the Server.
 */
function update_server_sample(int $serverAccessType): void
{
    // Create a client.
    $cloudFtpClient = new CloudFtpClient();

    // Prepare the request message.
    $server = (new Server())
        ->setAccessType($serverAccessType);
    $request = (new UpdateServerRequest())
        ->setServer($server);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudFtpClient->updateServer($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
{
    $serverAccessType = AccessType::ACCESS_TYPE_UNSPECIFIED;

    update_server_sample($serverAccessType);
}

Python

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。詳細については、Cloud FTP Python API リファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

# 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_update_server():
    # Create a client
    client = ftp_v1.CloudFtpClient()

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

    request = ftp_v1.UpdateServerRequest(
        server=server,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。詳細については、Cloud FTP Ruby API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/ftp/v1"

##
# Snippet for the update_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#update_server.
#
def update_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::UpdateServerRequest.new

  # Call the update_server method.
  result = client.update_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

内部サーバーのアクセスを更新する

gcloud

内部サーバーのアクセス構成を更新するには、gcloud alpha storage ftp servers update コマンドを実行します。--consumer-accept-list フラグを指定し、必要に応じて --consumer-reject-list フラグを指定します。

後述のコマンドデータを使用する前に、次のように置き換えます。

  • SERVER_ID: サーバー ID。
  • LOCATION_ID: サーバーのロケーション(us-west1 など)。
  • PROJECT_TO_ALLOW: Private Service Connect を使用してサーバーに接続できるコンシューマー プロジェクトのプロジェクト ID または番号。例: example-allowed-project少なくとも 1 つのプロジェクトを指定する必要があります。

    許可できるプロジェクトは最大 500 個です。複数のプロジェクトとそれぞれの接続上限をカンマ区切りのリストで指定します。例: --consumer-accept-list=projectA=20,projectB=15

  • CONNECTION_LIMIT: コンシューマー プロジェクトで作成できる Private Service Connect エンドポイントの最大数。値は 1 ~ 250 のエンドポイントにする必要があります。
  • (省略可)PROJECT_TO_REJECT: サーバーへの接続が禁止されているコンシューマ プロジェクトのプロジェクト ID またはプロジェクト番号。例: example-rejected-project。このリストに含まれるプロジェクトは、許可されたプロジェクトのリストに含まれていても、サーバーへのアクセスが拒否されます。

    拒否できるプロジェクトは最大 64 個です。複数のプロジェクトをカンマ区切りのリストで指定します。

    プロジェクトを明示的に拒否しない場合は、--consumer-reject-list フラグを省略します。

次のコマンドを実行します。

Linux、macOS、Cloud Shell

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID \
    --consumer-accept-list=PROJECT_TO_ALLOW=CONNECTION_LIMIT \
    --consumer-reject-list=PROJECT_TO_REJECT

Windows(PowerShell)

gcloud alpha storage ftp servers update SERVER_ID --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 update SERVER_ID --location=LOCATION_ID ^
    --consumer-accept-list=PROJECT_TO_ALLOW=CONNECTION_LIMIT ^
    --consumer-reject-list=PROJECT_TO_REJECT
サーバーが更新されるまでに数秒かかります。

REST

内部サーバーのアクセス構成を更新するには、servers.patch メソッドを使用します。updateMask クエリ パラメータに internalConfig フィールドを指定します。

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: サーバーの Google Cloud プロジェクト ID。
  • LOCATION_ID: サーバーのロケーション(us-west1 など)。
  • SERVER_ID: サーバー ID。
  • PROJECT_TO_ALLOW: Private Service Connect を使用してサーバーに接続できるコンシューマー プロジェクトのプロジェクト ID または番号。例: example-allowed-project少なくとも 1 つのプロジェクトを指定する必要があります。

    許可できるプロジェクトは最大 500 個です。

  • CONNECTION_LIMIT: コンシューマー プロジェクトで作成できる Private Service Connect エンドポイントの最大数。値は 1 ~ 250 のエンドポイントにする必要があります。
  • (省略可)PROJECT_TO_REJECT: サーバーへの接続が禁止されているコンシューマ プロジェクトのプロジェクト ID またはプロジェクト番号。例: example-rejected-project。このリストに含まれるプロジェクトは、許可されたプロジェクトのリストに含まれていても、サーバーへのアクセスが拒否されます。

    拒否できるプロジェクトは最大 64 件です。

    プロジェクトを明示的に拒否しない場合は、consumerRejectList オブジェクトを省略します。

HTTP メソッドと URL:

PATCH https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID?updateMask=internalConfig

リクエストの本文(JSON):

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

リクエストを送信するには、次のいずれかのオプションを展開します。

レスポンスで長時間実行オペレーションを識別できます。サーバーが更新されるまでに数秒かかります。

クライアント ライブラリ

C#

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。詳細については、Cloud FTP C# API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

public sealed partial class GeneratedCloudFtpClientSnippets
{
    /// <summary>Snippet for UpdateServerAsync</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 UpdateServerAsync()
    {
        // Create client
        CloudFtpClient cloudFtpClient = await CloudFtpClient.CreateAsync();
        // Initialize request argument(s)
        Server server = new Server();
        FieldMask updateMask = new FieldMask();
        // Make the request
        Operation<Server, OperationMetadata> response = await cloudFtpClient.UpdateServerAsync(server, updateMask);

        // 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.PollOnceUpdateServerAsync(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

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。詳細については、Cloud FTP Go API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


//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.UpdateServerRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/ftp/apiv1/ftppb#UpdateServerRequest.
	}
	op, err := c.UpdateServer(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

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

Java

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。詳細については、Cloud FTP Java API リファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.api.core.ApiFuture;
import com.google.cloud.ftp.v1.CloudFtpClient;
import com.google.cloud.ftp.v1.Server;
import com.google.cloud.ftp.v1.UpdateServerRequest;
import com.google.longrunning.Operation;
import com.google.protobuf.FieldMask;

public class AsyncUpdateServer {

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

  public static void asyncUpdateServer() 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()) {
      UpdateServerRequest request =
          UpdateServerRequest.newBuilder()
              .setUpdateMask(FieldMask.newBuilder().build())
              .setServer(Server.newBuilder().build())
              .setRequestId("requestId693933066")
              .build();
      ApiFuture<Operation> future = cloudFtpClient.updateServerCallable().futureCall(request);
      // Do something.
      Operation response = future.get();
    }
  }
}

Node.js

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。詳細については、Cloud FTP Node.js API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * 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.
 */
/**
 *  Optional. Field mask is used to specify the fields to be overwritten in the
 *  Server resource by the update.
 *  The fields specified in the update_mask are relative to the resource, not
 *  the full request. A field will be overwritten if it is in the mask. If the
 *  user does not provide a mask then all fields present in the request will be
 *  overwritten.
 */
// const updateMask = {}
/**
 *  Required. The resource being updated
 */
// 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 callUpdateServer() {
  // Construct request
  const request = {
    server,
  };

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

callUpdateServer();

PHP

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP PHP API リファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

/**
 * Updates the parameters of a single Server.
 *
 * @param int $serverAccessType The access type of the Server.
 */
function update_server_sample(int $serverAccessType): void
{
    // Create a client.
    $cloudFtpClient = new CloudFtpClient();

    // Prepare the request message.
    $server = (new Server())
        ->setAccessType($serverAccessType);
    $request = (new UpdateServerRequest())
        ->setServer($server);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudFtpClient->updateServer($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
{
    $serverAccessType = AccessType::ACCESS_TYPE_UNSPECIFIED;

    update_server_sample($serverAccessType);
}

Python

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP Python API のリファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

# 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_update_server():
    # Create a client
    client = ftp_v1.CloudFtpClient()

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

    request = ftp_v1.UpdateServerRequest(
        server=server,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Cloud FTP 用のクライアント ライブラリをインストールして使用する方法については、Cloud FTP クライアント ライブラリをご覧ください。 詳細については、Cloud FTP Ruby API リファレンス ドキュメントをご覧ください。

Cloud FTP に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/ftp/v1"

##
# Snippet for the update_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#update_server.
#
def update_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::UpdateServerRequest.new

  # Call the update_server method.
  result = client.update_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

サーバーの表示名を更新する

gcloud

SFTP サーバーの表示名などのメタデータを更新するには、gcloud alpha storage ftp servers update コマンドを実行します。

後述のコマンドデータを使用する前に、次のように置き換えます。

  • SERVER_ID: サーバー ID。
  • LOCATION_ID: サーバーのロケーション(us-west1 など)。
  • DISPLAY_NAME: サーバーの表示名。

次のコマンドを実行します。

Linux、macOS、Cloud Shell

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID \
    --display-name="DISPLAY_NAME"

Windows(PowerShell)

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID `
    --display-name="DISPLAY_NAME"

Windows(cmd.exe)

gcloud alpha storage ftp servers update SERVER_ID --location=LOCATION_ID ^
    --display-name="DISPLAY_NAME"
サーバーが更新されるまでに数秒かかります。

REST

SFTP サーバーの表示名などのメタデータを更新するには、servers.patch メソッドを使用します。updateMask クエリ パラメータに、更新するフィールドのカンマ区切りのリストを指定します。リクエストの本文で、設定する値を含む JSON オブジェクトを指定します。

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: サーバーの Google Cloud プロジェクト ID。
  • LOCATION_ID: サーバーのロケーション(us-west1 など)。
  • SERVER_ID: サーバー ID。
  • FIELDS_TO_UPDATE: 更新するフィールドのカンマ区切りのリスト(サーバー リソースを基準としたパス)。たとえば、表示名を更新するには、クエリ パラメータ updateMask=displayName を指定します。
  • DISPLAY_NAME: サーバーの表示名。

HTTP メソッドと URL:

PATCH https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID?updateMask=FIELDS_TO_UPDATE

リクエストの本文(JSON):

{
  "displayName": "DISPLAY_NAME"
}

リクエストを送信するには、次のいずれかのオプションを展開します。

レスポンスで長時間実行オペレーションを識別できます。サーバーの更新には数秒かかります。 <0