<h3 dir="auto">Body</h3>
<p dir="auto">issue is described in PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1337995923" data-permission-text="Title is private" data-url="https://github.com/apache/airflow/issues/25705" data-hovercard-type="pull_request" data-hovercard-url="/apache/airflow/pull/25705/hovercard" href="https://github.com/apache/airflow/pull/25705">#25705</a><br>
the author of the PR abandon it so anyone can try to submit a fix to the issue.</p>
<h3 dir="auto">Committer</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I acknowledge that I am a maintainer/committer of the Apache Airflow project.</li>
</ul>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.5.0</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">While creating SFTP sensor I have tried to find a file under directory. But I was getting error as Time Out, not found.<br>
So after debugging code found that there is a issue with <a href="https://airflow.apache.org/docs/apache-airflow-providers-sftp/stable/_modules/airflow/providers/sftp/sensors/sftp.html#SFTPSensor.poke" rel="nofollow">poke function</a>.</p>
<p dir="auto">As after getting matched file we are trying to find last modified time of the file using <a href="https://airflow.apache.org/docs/apache-airflow-providers-sftp/stable/_modules/airflow/providers/sftp/hooks/sftp.html#SFTPHook.get_mod_time" rel="nofollow">self.hook.get_mod_time</a> which take full path (path + filename) and we are giving only filename as arguments.</p>
<h3 dir="auto">What you think should happen instead</h3>
<p dir="auto">I have solved that issue by adding path with filename and then calling <a href="https://airflow.apache.org/docs/apache-airflow-providers-sftp/stable/_modules/airflow/providers/sftp/hooks/sftp.html#SFTPHook.get_mod_time" rel="nofollow">self.hook.get_mod_time</a> function.</p>
<p dir="auto">Here is modified code,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
def poke(self, context: Context) -&gt; bool:
        self.hook = SFTPHook(self.sftp_conn_id)
        self.log.info(&quot;Poking for %s, with pattern %s&quot;, self.path, self.file_pattern)

        if self.file_pattern:
            file_from_pattern = self.hook.get_file_by_pattern(self.path, self.file_pattern)
            if file_from_pattern:
                '''actual_file_to_check = file_from_pattern'''
                actual_file_to_check = self.path + file_from_pattern
            else:
                return False
        else:
            actual_file_to_check = self.path

        try:
            mod_time = self.hook.get_mod_time(actual_file_to_check)
            self.log.info(&quot;Found File %s last modified: %s&quot;, str(actual_file_to_check), str(mod_time))
        except OSError as e:
            if e.errno != SFTP_NO_SUCH_FILE:
                raise e
            return False
        self.hook.close_conn()
        if self.newer_than:
            _mod_time = convert_to_utc(datetime.strptime(mod_time, &quot;%Y%m%d%H%M%S&quot;))
            _newer_than = convert_to_utc(self.newer_than)
            return _newer_than &lt;= _mod_time
        else:
            return True
"><pre class="notranslate"><code class="notranslate">
def poke(self, context: Context) -&gt; bool:
        self.hook = SFTPHook(self.sftp_conn_id)
        self.log.info("Poking for %s, with pattern %s", self.path, self.file_pattern)

        if self.file_pattern:
            file_from_pattern = self.hook.get_file_by_pattern(self.path, self.file_pattern)
            if file_from_pattern:
                '''actual_file_to_check = file_from_pattern'''
                actual_file_to_check = self.path + file_from_pattern
            else:
                return False
        else:
            actual_file_to_check = self.path

        try:
            mod_time = self.hook.get_mod_time(actual_file_to_check)
            self.log.info("Found File %s last modified: %s", str(actual_file_to_check), str(mod_time))
        except OSError as e:
            if e.errno != SFTP_NO_SUCH_FILE:
                raise e
            return False
        self.hook.close_conn()
        if self.newer_than:
            _mod_time = convert_to_utc(datetime.strptime(mod_time, "%Y%m%d%H%M%S"))
            _newer_than = convert_to_utc(self.newer_than)
            return _newer_than &lt;= _mod_time
        else:
            return True

</code></pre></div>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">You can get same issue by creating a DAG as mentioned</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="with DAG(
        dag_id='sftp_sensor_dag',
        max_active_runs=1,
        default_args=default_args,
) as dag:
 file_sensing_task = SFTPSensor(
        task_id='sensor_for_file',
        path= &quot;Weekly/11/&quot;,
        file_pattern = &quot;*pdf*,
        sftp_conn_id='sftp_hook_conn',
        poke_interval=30
    )"><pre class="notranslate"><code class="notranslate">with DAG(
        dag_id='sftp_sensor_dag',
        max_active_runs=1,
        default_args=default_args,
) as dag:
 file_sensing_task = SFTPSensor(
        task_id='sensor_for_file',
        path= "Weekly/11/",
        file_pattern = "*pdf*,
        sftp_conn_id='sftp_hook_conn',
        poke_interval=30
    )
</code></pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Microsoft Windows [Version 10.0.19044.2251]</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Docker-Compose</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Anything else</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>