Skip to content

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

Closed
@Kaaly

Description

@Kaaly

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions