SFTP サーバーを開始または停止する

SFTP サーバーを停止または起動して、その状態を管理し、アクセスを制御して、費用を最適化できます。

サーバーを停止すると、アクセスが無効になり、リソースの使用量が削減されます。たとえば、サーバーへの不正アクセスが疑われる場合は、サーバーを停止して、アクティブな転送をすべて停止し、新しい接続をブロックできます。また、データ転送が予定されていない期間にサーバーを一時停止することで、サーバーの稼働時間費用を削減できます。

サーバーを起動すると、アクセスが復元され、ユーザーはサーバーに接続できるようになります。

必要なロール

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

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

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

サーバーを停止する

サーバーを停止すると、次のようになります。

  • アクセスが拒否され、アクティブな接続が切断されます。アクティブな接続があるユーザーには、次のようなエラー メッセージが表示されることがあります。

    Connection is terminated: Connection closed by remote host
    client_loop: send disconnect: Broken pipe
    Connection closed
    
  • 新しい接続を確立できません。

サーバーを停止する手順は次のとおりです。

REST

サーバーを停止するには、 servers.stop メソッドを使用します。

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

  • PROJECT_ID: サーバーの Google Cloud プロジェクト ID。
  • LOCATION_ID:サーバーのGoogle Cloud ロケーション(us-west1 など)。
  • SERVER_ID: サーバー ID。

HTTP メソッドと URL:

POST https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID:stop

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

レスポンスで 長時間実行オペレーションを識別できます。

クライアント ライブラリ

C#

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

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

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

public sealed partial class GeneratedCloudFtpClientSnippets
{
    /// <summary>Snippet for StopServerAsync</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 StopServerAsync()
    {
        // Create client
        CloudFtpClient cloudFtpClient = await CloudFtpClient.CreateAsync();
        // Initialize request argument(s)
        string name = "projects/[PROJECT]/locations/[LOCATION]/servers/[SERVER]";
        // Make the request
        Operation<Server, OperationMetadata> response = await cloudFtpClient.StopServerAsync(name);

        // 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.PollOnceStopServerAsync(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.StopServerRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/ftp/apiv1/ftppb#StopServerRequest.
	}
	op, err := c.StopServer(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.ServerName;
import com.google.cloud.ftp.v1.StopServerRequest;
import com.google.longrunning.Operation;

public class AsyncStopServer {

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

  public static void asyncStopServer() 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()) {
      StopServerRequest request =
          StopServerRequest.newBuilder()
              .setName(ServerName.of("[PROJECT]", "[LOCATION]", "[SERVER]").toString())
              .build();
      ApiFuture<Operation> future = cloudFtpClient.stopServerCallable().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.
 */
/**
 *  Required. Name of the resource.
 *  Format: `projects/{project}/locations/{location}/servers/{server}`
 */
// const name = 'abc123'

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

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

async function callStopServer() {
  // Construct request
  const request = {
    name,
  };

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

callStopServer();

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\StopServerRequest;
use Google\Rpc\Status;

/**
 * Stops an active Server.
 *
 * @param string $formattedName Name of the resource.
 *                              Format: `projects/{project}/locations/{location}/servers/{server}`
 *                              Please see {@see CloudFtpClient::serverName()} for help formatting this field.
 */
function stop_server_sample(string $formattedName): void
{
    // Create a client.
    $cloudFtpClient = new CloudFtpClient();

    // Prepare the request message.
    $request = (new StopServerRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudFtpClient->stopServer($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
{
    $formattedName = CloudFtpClient::serverName('[PROJECT]', '[LOCATION]', '[SERVER]');

    stop_server_sample($formattedName);
}

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

    # Initialize request argument(s)
    request = ftp_v1.StopServerRequest(
        name="name_value",
    )

    # Make the request
    operation = client.stop_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 stop_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#stop_server.
#
def stop_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::StopServerRequest.new

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

サーバーを起動する

REST

サーバーを起動するには、 servers.start メソッドを使用します。

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

  • PROJECT_ID: サーバーの Google Cloud プロジェクト ID。
  • LOCATION_ID:サーバーのGoogle Cloud ロケーション(us-west1 など)。
  • SERVER_ID: サーバー ID。

HTTP メソッドと URL:

POST https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID:start

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

レスポンスで 長時間実行オペレーションを識別できます。 サーバーが起動するまでに数分かかります。

クライアント ライブラリ

C#

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

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

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

public sealed partial class GeneratedCloudFtpClientSnippets
{
    /// <summary>Snippet for StartServerAsync</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 StartServerAsync()
    {
        // Create client
        CloudFtpClient cloudFtpClient = await CloudFtpClient.CreateAsync();
        // Initialize request argument(s)
        string name = "projects/[PROJECT]/locations/[LOCATION]/servers/[SERVER]";
        // Make the request
        Operation<Server, OperationMetadata> response = await cloudFtpClient.StartServerAsync(name);

        // 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.PollOnceStartServerAsync(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.StartServerRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/ftp/apiv1/ftppb#StartServerRequest.
	}
	op, err := c.StartServer(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.ServerName;
import com.google.cloud.ftp.v1.StartServerRequest;
import com.google.longrunning.Operation;

public class AsyncStartServer {

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

  public static void asyncStartServer() 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()) {
      StartServerRequest request =
          StartServerRequest.newBuilder()
              .setName(ServerName.of("[PROJECT]", "[LOCATION]", "[SERVER]").toString())
              .build();
      ApiFuture<Operation> future = cloudFtpClient.startServerCallable().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.
 */
/**
 *  Required. Name of the resource
 *  Format: `projects/{project}/locations/{location}/servers/{server}`
 */
// const name = 'abc123'

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

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

async function callStartServer() {
  // Construct request
  const request = {
    name,
  };

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

callStartServer();

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\StartServerRequest;
use Google\Rpc\Status;

/**
 * Starts a stopping/stopped Server.
 *
 * @param string $formattedName Name of the resource
 *                              Format: `projects/{project}/locations/{location}/servers/{server}`
 *                              Please see {@see CloudFtpClient::serverName()} for help formatting this field.
 */
function start_server_sample(string $formattedName): void
{
    // Create a client.
    $cloudFtpClient = new CloudFtpClient();

    // Prepare the request message.
    $request = (new StartServerRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudFtpClient->startServer($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
{
    $formattedName = CloudFtpClient::serverName('[PROJECT]', '[LOCATION]', '[SERVER]');

    start_server_sample($formattedName);
}

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

    # Initialize request argument(s)
    request = ftp_v1.StartServerRequest(
        name="name_value",
    )

    # Make the request
    operation = client.start_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 start_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#start_server.
#
def start_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::StartServerRequest.new

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

次のステップ