עדכון שרת SFTP

כדי לעדכן את המשתמשים שמורשים להתחבר לשרת Cloud FTP, צריך לעדכן את הגדרות הגישה של השרת. אתם יכולים גם לעדכן מטא-נתונים, כמו השם המוצג של השרת.

אחרי שיוצרים את השרת, אי אפשר לשנות את הסוג שלו (חיצוני או פנימי).

התפקידים הנדרשים

כדי לקבל את ההרשאות שנדרשות לעדכון שרת SFTP, צריך לבקש מהאדמין להקצות לכם ב-IAM את התפקיד אדמין של Cloud FTP (roles/ftp.admin) בפרויקט. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

זהו תפקיד מוגדר מראש שכולל את ההרשאות שנדרשות כדי לעדכן שרת SFTP. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

כדי לעדכן שרת SFTP, נדרשות ההרשאות הבאות:

  • ftp.servers.update
  • אם אתם משתמשים במסוף Google Cloud כדי לבצע את המשימה:
    • ftp.servers.list
    • ftp.servers.get

יכול להיות שתקבלו את ההרשאות האלה באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

עדכון הגישה לשרת חיצוני

המסוף

  1. נכנסים לדף Cloud FTP במסוף Google Cloud .

    מעבר אל Cloud FTP

  2. לוחצים על מזהה השרת.

  3. בקטע External config, לוחצים על  Edit external configuration.

  4. בשדה Allowed IP ranges, מציינים את כתובות ה-IP שמורשות לגשת לשרת:

    • כדי לאפשר גישה לטווח כתובות IP, צריך לספק בלוק CIDR ואז ללחוץ על Enter. לדוגמה, 192.0.2.0/24. כדי לאפשר חיבורים מכל כתובות ה-IP, משתמשים ב-0.0.0.0/0.

    • כדי להסיר את הגישה לטווח כתובות IP, לוחצים על  Remove.

    צריך לציין ערך אחד לפחות, ואפשר לציין עד 500 בלוקי CIDR.

  5. לוחצים על Save.

gcloud

כדי לעדכן את הגדרת הגישה לשרת חיצוני, מריצים את הפקודה gcloud alpha storage ftp servers update. מציינים את הדגל --allowed-cidr-blocks.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫SERVER_ID: מזהה השרת.
  • ‫LOCATION_ID: המיקום של השרת, למשל us-west1.
  • ‫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 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 של השרת.
  • ‫LOCATION_ID: המיקום של השרת, למשל us-west1.
  • ‫SERVER_ID: מזהה השרת.
  • ‫CIDR_BLOCK: בלוק CIDR שמורשה לגשת לשרת. לדוגמה: 192.0.2.0/24. צריך לציין ערך אחד לפחות, ואפשר לציין עד 500 בלוקי CIDR. כדי לאפשר חיבורים מכל כתובות ה-IP, משתמשים ב-0.0.0.0/0.

ה-method של ה-HTTP וכתובת ה-URL:

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

תוכן בקשת JSON:

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

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

התגובה מזהה פעולה ממושכת. לוקח לשרת כמה שניות להתעדכן.

ספריות לקוח

C#

במאמר ספריות הלקוח של Cloud FTP מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Cloud FTP. למידע נוסף, קראו את מאמרי העזרה של Cloud FTP C# API.

כדי לבצע אימות ב-Cloud FTP, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.


//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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

/**
 * 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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

# 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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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

איך מעדכנים את הגישה של שרת פנימי

המסוף

  1. נכנסים לדף Cloud FTP במסוף Google Cloud .

    מעבר אל Cloud FTP

  2. לוחצים על מזהה השרת.

  3. בקטע Internal config, לוחצים על  Edit internal configuration.

  4. בקטע Accepted projects, מציינים את הפרויקטים של הצרכנים שמורשים להתחבר לשרת באמצעות Private Service Connect:

    • כדי לאשר פרויקט:

      1. לוחצים על הוספת פרויקט שאושר.

      2. בשדה Project ID or number, מזינים את מזהה הפרויקט או המספר של פרויקט שמותר להתחבר אליו. לדוגמה, example-allowed-project.

      3. בשדה Connection limit, מזינים את המספר המקסימלי של נקודות קצה של Private Service Connect שאפשר ליצור בפרויקט של הצרכן. הערך צריך להיות בין נקודת קצה אחת ל-250 נקודות קצה.

    • כדי להסיר פרויקט שאושר, לוחצים על  Delete accepted project.

  5. (אופציונלי) בקטע Rejected projects, מציינים את הפרויקטים שאסור לחבר לשרת:

    • כדי לאסור על פרויקט, לוחצים על הוספת פרויקט שנדחה. מזינים את מזהה הפרויקט או את המספר של פרויקט הצרכן שאסור לו להתחבר לשרת.

      פרויקטים ברשימה הזו לא יכולים לגשת לשרת, גם אם הם כלולים ברשימת הפרויקטים המורשים.

    • כדי להסיר פרויקט אסור, לוחצים על  Delete rejected project.

  6. לוחצים על Save.

gcloud

כדי לעדכן את הגדרות הגישה לשרת פנימי, מריצים את הפקודה gcloud alpha storage ftp servers update. מציינים את הדגל --consumer-accept-list, ואם רוצים גם את הדגל --consumer-reject-list.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫SERVER_ID: מזהה השרת.
  • ‫LOCATION_ID: המיקום של השרת, למשל us-west1.
  • ‫PROJECT_TO_ALLOW: מזהה הפרויקט או מספר הפרויקט של הצרכן שמורשה להתחבר לשרת באמצעות Private Service Connect. לדוגמה, example-allowed-project. צריך לציין לפחות פרויקט אחד.

    אפשר לאשר עד 500 פרויקטים. צריך לציין כמה פרויקטים ואת מגבלות החיבורים שלהם ברשימה מופרדת בפסיקים. לדוגמה, --consumer-accept-list=projectA=20,projectB=15.

  • ‫CONNECTION_LIMIT: המספר המקסימלי של נקודות קצה מסוג Private Service Connect שאפשר ליצור בפרויקט הצרכן. הערך צריך להיות בין נקודת קצה אחת ל-250 נקודות קצה.
  • (אופציונלי) PROJECT_TO_REJECT: מזהה הפרויקט או מספר הפרויקט של הצרכן שאסור לו להתחבר לשרת. לדוגמה, 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 של השרת.
  • ‫LOCATION_ID: המיקום של השרת, למשל us-west1.
  • ‫SERVER_ID: מזהה השרת.
  • ‫PROJECT_TO_ALLOW: מזהה הפרויקט או מספר הפרויקט של הצרכן שמורשה להתחבר לשרת באמצעות Private Service Connect. לדוגמה, example-allowed-project. צריך לציין לפחות פרויקט אחד.

    אפשר לאשר עד 500 פרויקטים.

  • ‫CONNECTION_LIMIT: המספר המקסימלי של נקודות קצה מסוג Private Service Connect שאפשר ליצור בפרויקט הצרכן. הערך צריך להיות בין נקודת קצה אחת ל-250 נקודות קצה.
  • (אופציונלי) PROJECT_TO_REJECT: מזהה הפרויקט או מספר הפרויקט של הצרכן שאסור לו להתחבר לשרת. לדוגמה, example-rejected-project. פרויקטים ברשימה הזו לא יכולים לגשת לשרת, גם אם הם כלולים ברשימת הפרויקטים המורשים.

    אפשר לדחות עד 64 פרויקטים.

    אם אתם לא רוצים לדחות פרויקטים באופן מפורש, אל תכללו את האובייקט consumerRejectList.

ה-method של ה-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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.


//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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

/**
 * 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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

# 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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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

עדכון השם המוצג של השרת

המסוף

  1. נכנסים לדף Cloud FTP במסוף Google Cloud .

    מעבר אל Cloud FTP

  2. לוחצים על מזהה השרת.

  3. לוחצים על  עריכת השם המוצג.

  4. מזינים שם לתצוגה ולוחצים על שמירה.

gcloud

כדי לעדכן מטא-נתונים כמו השם המוצג של שרת SFTP, מריצים את הפקודה gcloud alpha storage ftp servers update.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫SERVER_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 של השרת.
  • ‫LOCATION_ID: המיקום של השרת, למשל us-west1.
  • ‫SERVER_ID: מזהה השרת.
  • ‫FIELDS_TO_UPDATE: רשימה מופרדת בפסיקים של שדות לעדכון, ביחס למשאב השרת. לדוגמה, כדי לעדכן את השם המוצג, צריך לציין את פרמטר השאילתה updateMask=displayName.
  • ‫DISPLAY_NAME: שם לתצוגה של השרת.

ה-method של ה-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"
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

התגובה מזהה פעולה ממושכת. לוקח כמה שניות עד שהשרת מתעדכן.