airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Improve SFTPOperator with directory transfer and DELETE operation

Open Dawnpool opened this issue 1 year ago • 1 comments

Description

Currently, the SFTPOperator in airflow providers does not support directory transfers. You have to specify every filename in a folder if you want to transfer the whole folder. Additionally, the operator supports only PUT and GET methods, not DELETE methods.

I think this operator would be more powerful if it could transfer an entire folder by specifying just the folder name as well as delete files and folders with DELETE method.

Use case/motivation

I want to copy a folder to an SFTP remote server using only the folder name. Before copying, I want to delete the already existing folder on the SFTP remote server to ensure it is overwritten.

Related issues

No response

Are you willing to submit a PR?

  • [X] Yes I am willing to submit a PR!

Code of Conduct

Dawnpool avatar Jun 21 '24 08:06 Dawnpool

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

boring-cyborg[bot] avatar Jun 21 '24 08:06 boring-cyborg[bot]

I think this operator would be more powerful if it could transfer an entire folder by specifying just the folder name as well as delete files and folders with DELETE method.

What are people doing currently to recursively obtain the list of all files in a remote directory on sftp server?

Would adding the MSLD command, to list the remote directory also be useful?

marcindulak avatar Jul 12 '24 18:07 marcindulak

Hi @marcindulak I am not sure what most people do to recursively obtain the list of all files in a directory, but I was considering writing a recursive function using depth-first search for that in this operator code. As you mentioned, adding the MSLD command would be very useful. I found that the describe_directory function in SFTPHook actually uses the MLSD command. However, from my research, only FTP supports MLSD, not SFTP, so, I am not sure if I would be able to use it. Thank you for your opinion, and please let me know if you have any further suggestions.

Dawnpool avatar Jul 15 '24 08:07 Dawnpool

Hi guys @potiuk @vatsrahul1001 @shahar1 @eladkal I am mentioning all of you because I am not sure who is mainly in charge of this feature. Can I create a PR for this one?

Dawnpool avatar Jul 15 '24 08:07 Dawnpool

Hi guys @potiuk @vatsrahul1001 @shahar1 @eladkal I am mentioning all of you because I am not sure who is mainly in charge of this feature. Can I create a PR for this one?

Feel free to create a PR - I'll be happy to review.

shahar1 avatar Jul 15 '24 08:07 shahar1

FYI @Dawnpool - it does not work like this. No-one is "in charge". Just create a PR and whoever will be available (and have time and feels like it's OK to do it will (at some point in time) review the PR. Just raise a PR and gently remind (in general) that it needs a review, rather than pinging individual people.

potiuk avatar Jul 15 '24 08:07 potiuk

FYI @Dawnpool - it does not work like this. No-one is "in charge". Just create a PR and whoever will be available (and have time and feels like it's OK to do it will (at some point in time) review the PR. Just raise a PR and gently remind (in general) that it needs a review, rather than pinging individual people.

Alright! I will keep that in mind. I will create a PR soon. Thanks for letting me know!

Dawnpool avatar Jul 16 '24 01:07 Dawnpool