Skip to content

SFTP doesn't return "." and ".." folder #1474

Open
@frozn

Description

@frozn

"OpenSSH for Windows" version
8.0.0.0 (v8.0.0.0p1-Beta)

Server OperatingSystem
Windows 10 Home

Client OperatingSystem
Windows 10 Home

What is failing
If connected over SFTP to the Win32-OpenSSH-Server, the folder doesn't contain the "." and ".." folder.

Expected output

Connected to xxx.
sftp> ls -la
drwx******    1 -        -            8192 Sep 29 21:26 .
drwx******    1 -        -            8192 Sep 29 21:26 ..
drwx******    1 -        -            8192 Sep 29 21:26 Miscellaneous
drwx******    1 -        -            8192 Sep 30 22:26 Working
sftp> 

Actual output

Connected to xxx.
sftp> ls -la
drwx******    1 -        -            8192 Sep 29 21:26 Miscellaneous
drwx******    1 -        -            8192 Sep 30 22:26 Working
sftp> 

Example if connected to OpenSSH-Server on a debian 10 system:

Connected to xxx.
sftp> ls -la
drwxr-xr-x    5 ncadmin  ncadmin      4096 Oct  1 20:42 .
drwxr-xr-x    3 root     root         4096 Sep 30 19:44 ..
-rw-------    1 ncadmin  ncadmin      1057 Oct  1 21:00 .bash_history
-rw-r--r--    1 ncadmin  ncadmin       220 Sep 30 19:44 .bash_logout
-rw-r--r--    1 ncadmin  ncadmin      3526 Sep 30 19:44 .bashrc
drwx------    3 ncadmin  ncadmin      4096 Sep 30 19:55 .gnupg
drwxr-xr-x    3 ncadmin  ncadmin      4096 Sep 30 19:58 .local
-rw-r--r--    1 ncadmin  ncadmin       807 Sep 30 19:44 .profile
drwx------    2 ncadmin  ncadmin      4096 Oct  1 20:42 .ssh
sftp> 

This behaviour leads to a problem in Nextcloud with external storages where deleting empty folders is not possible. I debugged it so far and found out, that the following code in the library "phpseclib" shows the problem:

https://github.com/phpseclib/phpseclib/blob/5ff9e7b48b5e20697d2aed9ba24760cd2e05d4b0/phpseclib/Net/SFTP.php#L2306-L2314

        $entries = $this->readlist($path, true);

        // normally $entries would have at least . and .. but it might not if the directories
        // permissions didn't allow reading
        if (empty($entries)) {
            return false;
        }

        unset($entries['.'], $entries['..']);

I think the problem lies in the Win32-OpenSSH-Server and not in Nextcloud or phpseclib.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions