refactor sftp subsystem request handling
Refactor the sftp subsystem request handling to make it more similar to an exec request. This simplifies and improves the readability of the code.
This commit is contained in:
parent
da223b9539
commit
e6a0e523e2
|
@ -159,26 +159,13 @@ func (c *adapter) handleSession(newChannel ssh.NewChannel) error {
|
|||
if len(sftpCmd) == 0 {
|
||||
sftpCmd = "/usr/lib/sftp-server -e"
|
||||
}
|
||||
cmd := &packer.RemoteCmd{
|
||||
Stdin: channel,
|
||||
Stdout: channel,
|
||||
Stderr: channel.Stderr(),
|
||||
Command: sftpCmd,
|
||||
}
|
||||
|
||||
c.ui.Say("starting sftp subsystem")
|
||||
if err := c.comm.Start(cmd); err != nil {
|
||||
c.ui.Error(err.Error())
|
||||
req.Reply(false, nil)
|
||||
close(done)
|
||||
return
|
||||
}
|
||||
|
||||
req.Reply(true, nil)
|
||||
go func() {
|
||||
cmd.Wait()
|
||||
_ = c.remoteExec(sftpCmd, channel, channel, channel.Stderr())
|
||||
close(done)
|
||||
}()
|
||||
req.Reply(true, nil)
|
||||
default:
|
||||
c.ui.Error(fmt.Sprintf("unsupported subsystem requested: %s", req.Payload))
|
||||
req.Reply(false, nil)
|
||||
|
|
Loading…
Reference in New Issue