Skip to content

Commit

Permalink
Merge pull request #564 from wwcd/master
Browse files Browse the repository at this point in the history
fix: sftp client hang when exit in sftp server example
  • Loading branch information
puellanivis committed Nov 9, 2023
2 parents b0487bc + d45e538 commit 1c8cffa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions examples/go-sftp-server/main.go
Expand Up @@ -17,7 +17,6 @@ import (

// Based on example server code from golang.org/x/crypto/ssh and server_standalone
func main() {

var (
readOnly bool
debugStderr bool
Expand Down Expand Up @@ -136,11 +135,12 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := server.Serve(); err == io.EOF {
server.Close()
log.Print("sftp client exited session.")
} else if err != nil {
log.Fatal("sftp server completed with error:", err)
if err := server.Serve(); err != nil {
if err != io.EOF {
log.Fatal("sftp server completed with error:", err)
}
}
server.Close()
log.Print("sftp client exited session.")
}
}
12 changes: 6 additions & 6 deletions examples/request-server/main.go
Expand Up @@ -17,7 +17,6 @@ import (

// Based on example server code from golang.org/x/crypto/ssh and server_standalone
func main() {

var (
readOnly bool
debugStderr bool
Expand Down Expand Up @@ -120,11 +119,12 @@ func main() {

root := sftp.InMemHandler()
server := sftp.NewRequestServer(channel, root)
if err := server.Serve(); err == io.EOF {
server.Close()
log.Print("sftp client exited session.")
} else if err != nil {
log.Fatal("sftp server completed with error:", err)
if err := server.Serve(); err != nil {
if err != io.EOF {
log.Fatal("sftp server completed with error:", err)
}
}
server.Close()
log.Print("sftp client exited session.")
}
}

0 comments on commit 1c8cffa

Please sign in to comment.