Hi there,
I have written a simple sshd which can handle shell sessions and the execution of commands.
But i have a problem with the scp command.
If i try to copy something from a client computer to the server with my simplesshd running it creates the file at the correct location but without any content in it. The file is 0kb. The same happens if i try to copy a directory recusively.
This is how i execute the scp command, which i run on the client:
scp -P 2200 test.file user@localhost:/home/user/
Here is the function that handles the exec command within my simplesshd.go:
func executeCommand(name string, args []string, c ssh.Channel) {
cmd := exec.Command(name, args...)
cmdChannel, err := pty.Start(cmd)
if err != nil {
log.Printf("Could not start pty %s", err)
c.Close()
return
}
close := func() {
c.Close()
}
var once sync.Once
go func() {
io.Copy(c, cmdChannel)
once.Do(close)
}()
go func() {
io.Copy(cmdChannel, c)
once.Do(close)
}()
}
pty.Start is a function from the package GitHub - kr/pty: PTY interface for Go
Here is a gist of a simplified version of simplesshd.go: gist
How can i fix/handle the scp command within my simplesshd to work as expected?
Thanks in advance!