2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-03 01:20:49 +00:00
restic/Godeps/_workspace/src/github.com/pkg/sftp/server_standalone/main.go
2016-02-13 19:11:35 +01:00

41 lines
805 B
Go

package main
// small wrapper around sftp server that allows it to be used as a separate process subsystem call by the ssh server.
// in practice this will statically link; however this allows unit testing from the sftp client.
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/pkg/sftp"
)
func main() {
var (
readOnly bool
debugStderr bool
)
flag.BoolVar(&readOnly, "R", false, "read-only server")
flag.BoolVar(&debugStderr, "e", false, "debug to stderr")
flag.Parse()
debugStream := ioutil.Discard
if debugStderr {
debugStream = os.Stderr
}
svr, _ := sftp.NewServer(
os.Stdin,
os.Stdout,
sftp.WithDebug(debugStream),
sftp.ReadOnly(),
)
if err := svr.Serve(); err != nil {
fmt.Fprintf(debugStream, "sftp server completed with error: %v", err)
os.Exit(1)
}
}