symfony: [FINDER] SSH2 Protocol - Date filter or $file->getMTime() not working if using subfolders

Symfony version(s) affected

6.4

Description

Hi,

when using Finder with ssh2 protocol, we can’t use it to filter files by last modification date and we can’t use $file->getMTime();

Exemple of code :

$finder = new Finder();
$connection = ssh2_connect('HOST', 'PORT');
ssh2_auth_password($connection,'USERNAME', 'PASSWORD');
$sftp = ssh2_sftp($connection);

$finder->in('ssh2.sftp://' . intval($sftp).'/subfolder/')->files();

if ($finder->count() > 0) {
    foreach ($finder as $file) {
        $mTime = $file->getMTime();
    }
}

We got this error : SplFileInfo::getMTime(): stat failed for ssh2.sftp://1133/subfolder/\exemple.pdf

Error seems to come from /\ just before file name.

For exemple, this code work :

$finder = new Finder();
$connection = ssh2_connect('HOST', 'PORT');
ssh2_auth_password($connection,'USERNAME', 'PASSWORD');
$sftp = ssh2_sftp($connection);

$finder->in('ssh2.sftp://' . intval($sftp).'/subfolder/')->files();

if ($finder->count() > 0) {
    foreach ($finder as $file) {
        $statinfo = ssh2_sftp_stat($sftp, '/subfolder/'. $file->getFilename());;
    }
}

In the same way, if we use date method to filter files directly from finder, finder return no file.

How to reproduce

Try to get last modification date from files in subfolder of a sftp

Possible Solution

Fix pathname to avoid back slash

Additional Context

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I get the same error on WAMP i.e. Windows. When I look for all files (should be files foo and bar) in folder subfolder of user george I get this:

SplFileInfo::getMTime(): stat failed for ssh2.sftp://237/home/george/subfolder/\foo