mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
add support for virtual folders
directories outside the user home directory can be exposed as virtual folders
This commit is contained in:
@@ -17,6 +17,8 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -248,3 +250,28 @@ func GenerateECDSAKeys(file string) error {
|
||||
}
|
||||
return ioutil.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600)
|
||||
}
|
||||
|
||||
// GetDirsForSFTPPath returns all the directory for the given path in reverse order
|
||||
// for example if the path is: /1/2/3/4 it returns:
|
||||
// [ "/1/2/3/4", "/1/2/3", "/1/2", "/1", "/" ]
|
||||
func GetDirsForSFTPPath(p string) []string {
|
||||
sftpPath := CleanSFTPPath(p)
|
||||
dirsForPath := []string{sftpPath}
|
||||
for {
|
||||
if sftpPath == "/" {
|
||||
break
|
||||
}
|
||||
sftpPath = path.Dir(sftpPath)
|
||||
dirsForPath = append(dirsForPath, sftpPath)
|
||||
}
|
||||
return dirsForPath
|
||||
}
|
||||
|
||||
// CleanSFTPPath returns a clean sftp path
|
||||
func CleanSFTPPath(p string) string {
|
||||
sftpPath := filepath.ToSlash(p)
|
||||
if !path.IsAbs(p) {
|
||||
sftpPath = "/" + sftpPath
|
||||
}
|
||||
return path.Clean(sftpPath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user