server_standalone: handle readonly properly

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
This commit is contained in:
unclejack 2017-03-15 15:31:42 +02:00 committed by John Eikenberry
parent 8f9da7f630
commit 62d5779aab
1 changed files with 7 additions and 2 deletions

View File

@ -18,6 +18,7 @@ func main() {
readOnly bool
debugStderr bool
debugLevel string
options []sftp.ServerOption
)
flag.BoolVar(&readOnly, "R", false, "read-only server")
@ -29,6 +30,11 @@ func main() {
if debugStderr {
debugStream = os.Stderr
}
options = append(options, sftp.WithDebug(debugStream))
if readOnly {
options = append(options, sftp.ReadOnly())
}
svr, _ := sftp.NewServer(
struct {
@ -37,8 +43,7 @@ func main() {
}{os.Stdin,
os.Stdout,
},
sftp.WithDebug(debugStream),
sftp.ReadOnly(),
options...,
)
if err := svr.Serve(); err != nil {
fmt.Fprintf(debugStream, "sftp server completed with error: %v", err)