server_standalone: handle readonly properly
Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
diff --git a/server_standalone/main.go b/server_standalone/main.go
index 646e99d..0b8e102 100644
--- a/server_standalone/main.go
+++ b/server_standalone/main.go
@@ -18,6 +18,7 @@
readOnly bool
debugStderr bool
debugLevel string
+ options []sftp.ServerOption
)
flag.BoolVar(&readOnly, "R", false, "read-only server")
@@ -29,6 +30,11 @@
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 @@
}{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)