yuseok89 commented on code in PR #77716: URL: https://github.com/apache/airflow/pull/77716#discussion_r4727923089
########## providers/ftp/src/airflow/providers/ftp/fs/ftp.py: ########## @@ -0,0 +1,64 @@ +# 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__ import annotations + +from typing import TYPE_CHECKING, Any + +from fsspec.implementations.ftp import FTPFileSystem + +from airflow.providers.common.compat.sdk import BaseHook +from airflow.providers.ftp.hooks.ftp import _get_passive_mode + +if TYPE_CHECKING: + from fsspec import AbstractFileSystem + +schemes = ["ftp"] + + +class _ActiveModeFTPFileSystem(FTPFileSystem): + """ + ``FTPFileSystem`` that turns passive mode off on every connection. + + fsspec has no option for it and keeps the ``ftplib`` default (passive), while ``FTPHook`` + honors the ``passive`` connection extra. ``_connect`` also runs when a read reconnects. + """ + + def _connect(self) -> None: + super()._connect() + self.ftp.set_pasv(False) + + +def get_fs(conn_id: str | None, storage_options: dict[str, Any] | None = None) -> AbstractFileSystem: Review Comment: Thanks for digging into this. I could reproduce it against vsftpd with a short idle timeout, and went with your suggestion. There is now one subclass for both modes, with `passive` as a constructor argument, and `ls` and `_open` send a `NOOP` first and reconnect through `_connect` when the server has closed the connection. With the same steps, the folder is now listed and the file is read as expected. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
