PowerShell / PowerShell/Win32-OpenSSH

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

Open
#1,474 1 comment 0 reactions 1 assignee View on GitHub

@bagajjal is already working on this.

Since Jul 9, 2020.

Area-SFTP Issue-Enhancement
Dominant language
No language data
Stars
8.3k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

"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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.