airflow.providers.google.cloud.transfers.gcs_to_sftp

此模組包含 Google Cloud Storage 至 SFTP 運算子。

模組內容

類別

GCSToSFTPOperator

將檔案從 Google Cloud Storage 儲存桶傳輸到 SFTP 伺服器。

屬性

WILDCARD

airflow.providers.google.cloud.transfers.gcs_to_sftp.WILDCARD = '*'[來源]
class airflow.providers.google.cloud.transfers.gcs_to_sftp.GCSToSFTPOperator(*, source_bucket, source_object, destination_path, keep_directory_structure=True, move_object=False, gcp_conn_id='google_cloud_default', sftp_conn_id='ssh_default', impersonation_chain=None, **kwargs)[來源]

基底類別: airflow.models.BaseOperator

將檔案從 Google Cloud Storage 儲存桶傳輸到 SFTP 伺服器。

with models.DAG(
    "example_gcs_to_sftp",
    start_date=datetime(2020, 6, 19),
    schedule=None,
) as dag:
    # downloads file to /tmp/sftp/folder/subfolder/file.txt
    copy_file_from_gcs_to_sftp = GCSToSFTPOperator(
        task_id="file-copy-gsc-to-sftp",
        source_bucket="test-gcs-sftp-bucket-name",
        source_object="folder/subfolder/file.txt",
        destination_path="/tmp/sftp",
    )

    # moves file to /tmp/data.txt
    move_file_from_gcs_to_sftp = GCSToSFTPOperator(
        task_id="file-move-gsc-to-sftp",
        source_bucket="test-gcs-sftp-bucket-name",
        source_object="folder/subfolder/data.txt",
        destination_path="/tmp",
        move_object=True,
        keep_directory_structure=False,
    )

參見

有關如何使用此運算子的更多資訊,請參閱指南: 運算子

參數
  • source_bucket (str) – 物件來源 Google Cloud Storage 儲存桶。(範本化)

  • source_object (str) – 要在 Google Cloud Storage 儲存桶中複製的物件來源名稱。(範本化)您只能為儲存桶中的物件(檔案名稱)使用一個萬用字元。萬用字元可以出現在物件名稱內部或物件名稱的末尾。不支援將萬用字元附加到儲存桶名稱。

  • destination_path (str) – sftp 遠端路徑。這是用於上傳到 SFTP 伺服器的指定目錄路徑。

  • keep_directory_structure (bool) – (選用)設定為 False 時,儲存桶上檔案的路徑會在 destination_path 中傳遞的路徑內重新建立。

  • move_object (bool) – 當 move object 為 True 時,物件將被移動而不是複製到新位置。這相當於 mv 命令,而不是 cp 命令。

  • gcp_conn_id (str) – (選用)用於連線到 Google Cloud 的連線 ID。

  • sftp_conn_id (str) – sftp 連線 ID。用於建立與 SFTP 伺服器連線的名稱或識別符。

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬使用短期憑證,或取得列表中最後一個帳戶的 access_token 所需的鏈結帳戶列表,該帳戶將在請求中被模擬。 如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。 如果設定為序列,則列表中的身分必須將「服務帳戶權杖建立者」IAM 角色授予緊鄰的前一個身分,列表中的第一個帳戶將此角色授予原始帳戶(範本化)。

template_fields: collections.abc.Sequence[str] = ('source_bucket', 'source_object', 'destination_path', 'impersonation_chain')[來源]
ui_color = '#f0eee4'[來源]
execute(context)[來源]

在建立運算子時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多上下文。

此條目是否有幫助?