unix 在Airflow中从一台服务器到另一台服务器的文件传输

c2e8gylq  于 11个月前  发布在  Unix
关注(0)|答案(2)|浏览(195)

我有一个文件(file.txt)存在于server 1与用户ID为“username 1”在路径(/home/A/file1.txt),并希望将此文件传输到其他服务器“server 2”与用户ID为“username 2”,并希望将文件放置在路径(/home/B/).我已经写了下面的代码,它不按预期工作.我哪里出错了?

import airflow
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
from airflow.contrib.operators.ssh_operator import SSHOperator
from airflow.contrib.hooks.ssh_hook import SSHHook
from airflow.contrib.sensors.sftp_sensor import SFTPSensor

default_args = {
         'owner': 'john',
         'depends_on_past': False,
         'email': [''],
         'email_on_failure': False,
         'email_on_retry': False,
         'retries': 0,
         'retry_delay': timedelta(minutes=5)
       }

  dag = DAG(
    'file transfer',
    default_args = default_args,
    description='A file transfer',
    schedule_interval=None)

 bash_file_transfer = """
  cp server1@username1:/home/A/file1.txt server2@username2:/home/B/  
  """

t1 = SSHOperator(
        ssh_conn_id='server1_conn'
        task_id='connected_to_server1'
        dag=dag
        )

t2 = SFTPOperator(
        sftp_conn_id='server2_conn'
        task_id='transfer file from server1 to server2'
        command=bash_file_transfer,
        dag=dag
        )

t1 >> t2

字符串

vi4fp9gy

vi4fp9gy1#

我认为你的错误是在bash_file_transfer声明上。应该是scp,而不是cp

d7v8vwbk

d7v8vwbk2#

SFTP操作符缺少关键字参数“local_filepath”,“remote_filepath”根据https://airflow.apache.org/docs/apache-airflow-providers-sftp/stable/_api/airflow/providers/sftp/operators/sftp/index.html,以上参数是必需的

相关问题