add dot and dot dot directories to sftp/ftp file listing

This commit is contained in:
Nicola Murino
2021-07-31 09:42:23 +02:00
parent f778e47d22
commit a26962f367
9 changed files with 71 additions and 22 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/drakkan/sftpgo/v2/common"
"github.com/drakkan/sftpgo/v2/dataprovider"
"github.com/drakkan/sftpgo/v2/logger"
"github.com/drakkan/sftpgo/v2/util"
"github.com/drakkan/sftpgo/v2/vfs"
)
@@ -21,10 +22,11 @@ type Connection struct {
// client's version string
ClientVersion string
// Remote address for this connection
RemoteAddr net.Addr
LocalAddr net.Addr
channel io.ReadWriteCloser
command string
RemoteAddr net.Addr
LocalAddr net.Addr
channel io.ReadWriteCloser
command string
folderPrefix string
}
// GetClientVersion returns the connected client's version
@@ -201,6 +203,11 @@ func (c *Connection) Filelist(request *sftp.Request) (sftp.ListerAt, error) {
if err != nil {
return nil, err
}
now := time.Now()
if request.Filepath != "/" || c.folderPrefix != "" {
files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, now, false))
}
files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, now, false))
return listerAt(files), nil
case "Stat":
if !c.User.HasPerm(dataprovider.PermListItems, path.Dir(request.Filepath)) {