I'm trying to run scp as command via golang's exec.cmd because the non-official implementations available for scp transfer did not work for me. Scp executes until it asks for the password and then I'm unable to write data to the stdin. Could it be possible that the stdin is redirected somewhere else?
var cmd *exec.Cmd
if m.IsDir() {
cmd = exec.Command("scp", "-r", src, user+"@"+client.Host+":"+dest)
} else {
cmd = exec.Command("scp", src, user+"@"+client.Host+":"+dest)
}
cmdWriter, err := cmd.StdinPipe()
if err != nil {
return err
}
err = cmd.Start()
if cred.Typ() == "PW" {
cmdWriter.Write( []byte(cred.Data()+"\n") )
} else {
log.Println( "credential typ not supported" )
}
err = cmd.Wait()
log.Println( "done" )
return err
Setting cmd.Stdin to os.Stdin works but of course I have to manually enter the password which is not what I want. Or would you overall not recommend this way to run scp? I'm able to run simple SSH commands on the server (with "golang.org/x/crypto/ssh"). Is there maybe a way to transfer binaries just via a SSH session? Thanks in advance.