问题描述
使用Apache airflow工具,如何为以下Python代码实现DAG。代码中完成的任务是将目录从GPU服务器获取到本地系统。代码在Jupyter笔记本中运行正常。请帮助在Airflow中实施...我对此很陌生。谢谢。
import pysftp
import os
myHostname = "hostname"
myUsername = "username"
myPassword = "pwd"
with pysftp.Connection(host=myHostname,username=myUsername,password=myPassword) as sftp:
print("Connection successfully stablished ... ")
src = '/path/src/'
dst = '/home/path/path/destination'
os.mkdir(dst)
sftp.get_d(src,dst,preserve_mtime=True)
print("Fetched source images from GPU server to local directory")
# connection closed automatically at the end of the with-block```
解决方法
- 对于SFTP职责,Airflow提供了
SFTOperator
,您可以直接使用。 - 或者,它对应的
SFTPHook
可以与简单的PythonOperator
一起使用