airflow.providers.google.cloud.transfers.gcs_to_sftp

此模块包含 Google Cloud Storage 到 SFTP 的 Operator。

属性

WILDCARD

GCSToSFTPOperator

将文件从 Google Cloud Storage 存储桶传输到 SFTP 服务器。

模块内容

airflow.providers.google.cloud.transfers.gcs_to_sftp.WILDCARD = '*'[source]
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)[source]

基类: 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,
    )

另请参阅

有关如何使用此 Operator 的更多信息,请参阅指南: Operator

参数:
  • 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 所需的链式账号列表,最后一个账号将在请求中被模拟。如果设置为字符串,该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,列表中的身份必须授予紧接其前的身份 Service Account Token Creator IAM 角色,列表中的第一个账号将此角色授予发起账号。(模板化)

template_fields: collections.abc.Sequence[str] = ('source_bucket', 'source_object', 'destination_path', 'impersonation_chain')[source]
ui_color = '#f0eee4'[source]
source_bucket[source]
source_object[source]
destination_path[source]
keep_directory_structure = True[source]
move_object = False[source]
gcp_conn_id = 'google_cloud_default'[source]
sftp_conn_id = 'ssh_default'[source]
impersonation_chain = None[source]
sftp_dirs = None[source]
property sftp_hook[source]
execute(context)[source]

创建 Operator 时派生。

上下文与渲染 jinja 模板时使用的字典相同。

有关更多上下文信息,请参阅 get_template_context。

get_openlineage_facets_on_start()[source]

此条目有帮助吗?