Source code for airflow.providers.amazon.aws.transfers.s3_to_sftp
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.from__future__importannotationsfromtempfileimportNamedTemporaryFilefromtypingimportTYPE_CHECKING,Sequencefromurllib.parseimporturlsplitfromairflow.modelsimportBaseOperatorfromairflow.providers.amazon.aws.hooks.s3importS3Hookfromairflow.providers.ssh.hooks.sshimportSSHHookifTYPE_CHECKING:fromairflow.utils.contextimportContext
[docs]classS3ToSFTPOperator(BaseOperator):""" This operator enables the transferring of files from S3 to a SFTP server. .. seealso:: For more information on how to use this operator, take a look at the guide: :ref:`howto/operator:S3ToSFTPOperator` :param sftp_conn_id: The sftp connection id. The name or identifier for establishing a connection to the SFTP server. :param sftp_path: The sftp remote path. This is the specified file path for uploading file to the SFTP server. :param aws_conn_id: The Airflow connection used for AWS credentials. If this is None or empty then the default boto3 behaviour is used. If running Airflow in a distributed manner and aws_conn_id is None or empty, then default boto3 configuration would be used (and must be maintained on each worker node). :param s3_bucket: The targeted s3 bucket. This is the S3 bucket from where the file is downloaded. :param s3_key: The targeted s3 key. This is the specified file path for downloading the file from S3. """
[docs]defget_s3_key(s3_key:str)->str:"""Parse the correct format for S3 keys regardless of how the S3 url is passed."""parsed_s3_key=urlsplit(s3_key)returnparsed_s3_key.path.lstrip("/")