יצירת שרת SFTP פנימי

במאמר הזה מוסבר איך ליצור שרת SFTP פנימי באמצעות Cloud FTP. אפשר לגשת לשרת SFTP פנימי רק בתוך רשת הענן הווירטואלי הפרטי (VPC) באמצעות Private Service Connect. עובדים ובעלי עניין פנימיים שנמצאים ברשת שלכם יכולים להשתמש בשרת כדי להעביר קבצים באופן מאובטח אל Cloud Storage וממנו.

אתם מציינים את הפרויקטים שמורשים להתחבר לשרת. אפשר גם לציין פרויקטים שלא יאושרו לקישור.

מידע רקע על VPC זמין בסקירה הכללית על VPC.

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

לפני שמתחילים

המסוף

  1. נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  5. Enable the Cloud FTP API, 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. אוספים את המידע הבא על המשתמשים בשרת:

    • רשימה של מזהי פרויקטים או מספרי פרויקטים שמורשים לגשת לשרת.
    • (אופציונלי) רשימה של מזהי פרויקטים או מספרי פרויקטים שנדחתה הגישה שלהם לשרת.

gcloud

  1. נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. התקינו את ה-CLI של Google Cloud.

  3. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  4. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  5. יוצרים או בוחרים פרויקט ב- Google Cloud .

    התפקידים שנדרשים כדי לבחור או ליצור פרויקט

    • בחירת פרויקט: כדי לבחור פרויקט לא נדרש תפקיד IAM ספציפי – אתם יכולים לבחור כל פרויקט שקיבלתם בו תפקיד.
    • יצירת פרויקט: כדי ליצור פרויקט, צריך את התפקיד "יצירת פרויקטים" (roles/resourcemanager.projectCreator), שכולל את ההרשאה resourcemanager.projects.create. איך מקצים תפקידים?
    • יוצרים פרויקט ב- Google Cloud :

      gcloud projects create PROJECT_ID

      מחליפים את PROJECT_ID בשם של הפרויקט ב- Google Cloud שאתם יוצרים.

    • בוחרים את הפרויקט שיצרתם ב- Google Cloud :

      gcloud config set project PROJECT_ID

      מחליפים את PROJECT_ID בשם הפרויקט ב- Google Cloud .

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

  7. מוודאים שהחיוב מופעל בפרויקט ב- Google Cloud .

  8. מפעילים את Cloud FTP API, אם הוא עדיין לא מופעל:

    התפקידים שנדרשים כדי להפעיל ממשקי API

    כדי להפעיל ממשקי API, צריך את ההרשאה serviceusage.services.enable. אם אתם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד "בעלים" (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד "אדמין בממשק 'שימוש בשירות'" (roles/serviceusage.serviceUsageAdmin). איך מקצים תפקידים

    gcloud services enable ftp.googleapis.com
  9. התקינו את ה-CLI של Google Cloud.

  10. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  11. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  12. יוצרים או בוחרים פרויקט ב- Google Cloud .

    התפקידים שנדרשים כדי לבחור או ליצור פרויקט

    • בחירת פרויקט: כדי לבחור פרויקט לא נדרש תפקיד IAM ספציפי – אתם יכולים לבחור כל פרויקט שקיבלתם בו תפקיד.
    • יצירת פרויקט: כדי ליצור פרויקט, צריך את התפקיד "יצירת פרויקטים" (roles/resourcemanager.projectCreator), שכולל את ההרשאה resourcemanager.projects.create. איך מקצים תפקידים?
    • יוצרים פרויקט ב- Google Cloud :

      gcloud projects create PROJECT_ID

      מחליפים את PROJECT_ID בשם של הפרויקט ב- Google Cloud שאתם יוצרים.

    • בוחרים את הפרויקט שיצרתם ב- Google Cloud :

      gcloud config set project PROJECT_ID

      מחליפים את PROJECT_ID בשם הפרויקט ב- Google Cloud .

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

  14. מוודאים שהחיוב מופעל בפרויקט ב- Google Cloud .

  15. מפעילים את Cloud FTP API, אם הוא עדיין לא מופעל:

    התפקידים שנדרשים כדי להפעיל ממשקי API

    כדי להפעיל ממשקי API, צריך את ההרשאה serviceusage.services.enable. אם אתם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד "בעלים" (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד "אדמין בממשק 'שימוש בשירות'" (roles/serviceusage.serviceUsageAdmin). איך מקצים תפקידים

    gcloud services enable ftp.googleapis.com
  16. אוספים את המידע הבא על המשתמשים בשרת:

    • רשימה של מזהי פרויקטים או מספרי פרויקטים שמורשים לגשת לשרת.
    • (אופציונלי) רשימה של מזהי פרויקטים או מספרי פרויקטים שנדחתה הגישה שלהם לשרת.

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

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

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

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

כדי ליצור שרת SFTP, צריך את ההרשאות הבאות:

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

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

יצירת שרת פנימי

המסוף

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

    מעבר אל Cloud FTP

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

  3. בכרטיסייה Server configuration, מזינים את הפרטים הבסיסיים של השרת:

    1. בשדה מזהה השרת, מזינים מזהה ייחודי לשרת.

    2. ברשימה Region, בוחרים את Google Cloud המיקום של השרת.

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

    3. (אופציונלי) מזינים שם לתצוגה של השרת.

    4. לוחצים על Continue.

  4. בכרטיסייה Networking and security, מגדירים את הקישוריות לשרת:

    1. בוחרים באפשרות Internal (VPC only).

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

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

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

      3. כדי להוסיף עוד פרויקטים, לוחצים על Add accepted project וחוזרים על השלבים הקודמים.

    3. (אופציונלי) כדי למנוע מפרויקטים להתחבר לשרת, בקטע Rejected projects לוחצים על Add rejected project. מזינים את מזהה הפרויקט או את מספר הפרויקט של הצרכן שאסור לו להתחבר לשרת.

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

  5. לוחצים על יצירה.

    יצירת השרת נמשכת כ-10 דקות.

gcloud

כדי ליצור שרת פנימי, מריצים את הפקודה gcloud alpha storage ftp servers create ומציינים את הדגל --access-type=INTERNAL.

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

  • ‫SERVER_ID: מזהה ייחודי של השרת. השם חייב להתחיל באות קטנה ולהסתיים באות קטנה או במספר. הוא יכול להכיל אותיות קטנות, מספרים ומקפים. לא יכול להתחיל בתחילית goog או להכיל את המחרוזת google, כולל שגיאות איות דומות כמו g00gle. האורך המקסימלי הוא 30 תווים.
  • ‫LOCATION_ID: Google Cloud המיקום של השרת, למשל us-west1.

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

  • ‫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 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

יצירת השרת נמשכת כ-10 דקות.

REST

כדי ליצור שרת פנימי, משתמשים ב-method ‏servers.create ומספקים הגדרת גישה מסוג internalConfig.

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

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud של השרת.
  • ‫LOCATION_ID: Google Cloud המיקום של השרת, למשל us-west1.

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

  • ‫SERVER_ID: מזהה ייחודי של השרת. השם חייב להתחיל באות קטנה ולהסתיים באות קטנה או במספר. הוא יכול להכיל אותיות קטנות, מספרים ומקפים. לא יכול להתחיל בתחילית goog או להכיל את המחרוזת google, כולל שגיאות איות דומות כמו g00gle. האורך המקסימלי הוא 30 תווים.
  • ‫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:

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

תוכן בקשת JSON:

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

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

התגובה מזהה פעולה ממושכת.

יצירת השרת נמשכת כ-10 דקות.

ספריות לקוח

כדי ליצור שרת פנימי, מגדירים את סוג הגישה כפנימי ומספקים הגדרת גישה פנימית.

C#

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

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

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

כדי ללמוד איך מתקינים את ספריית הלקוח ואיך משתמשים בה ב-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.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

כדי ללמוד איך מתקינים את ספריית הלקוח ואיך משתמשים בה ב-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.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

כדי ללמוד איך מתקינים את ספריית הלקוח ואיך משתמשים בה ב-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.
 */
/**
 *  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

כדי ללמוד איך מתקינים את ספריית הלקוח ואיך משתמשים בה ב-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\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

כדי ללמוד איך מתקינים את ספריית הלקוח ואיך משתמשים בה ב-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_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

כדי ללמוד איך מתקינים את ספריית הלקוח ואיך משתמשים בה ב-Cloud FTP, ראו: ספריות לקוח של Cloud FTP. למידע נוסף, קראו את מאמרי העזרה של Cloud FTP Ruby API.

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

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

המאמרים הבאים