import ( "golang.org/x/crypto/ssh" ) // create a new SSH client config config := &ssh.ClientConfig{ User: "username", Auth: []ssh.AuthMethod{ ssh.Password("password"), }, } // connect to the SSH server client, err := ssh.Dial("tcp", "example.com:22", config) if err != nil { panic(err) } defer client.Close() // request a TCP forwarding channel channel, reqs, err := client.OpenChannel("tcpip-forward", []byte("127.0.0.1:8080"), ssh.Marshal(&ssh.ChannelRequestTcpipForward{})) if err != nil { panic(err) } defer channel.Close() // handle any extension requests from the server go func() { for req := range reqs { if req.Type == "[email protected]" { req.Reply(true, nil) } } }()
import ( "golang.org/x/crypto/ssh" ) // create a new SSH client config config := &ssh.ClientConfig{ User: "username", Auth: []ssh.AuthMethod{ ssh.Password("password"), }, } // connect to the SSH server client, err := ssh.Dial("tcp", "example.com:22", config) if err != nil { panic(err) } defer client.Close() // request a subsystem channel channel, reqs, err := client.OpenChannel("subsystem", []byte("sftp"), ssh.Marshal(&ssh.SubsystemRequest{})) if err != nil { panic(err) } defer channel.Close() // handle any extension requests from the server go func() { for req := range reqs { if req.Type == "[email protected]" { req.Reply(true, nil) } } }()This example demonstrates how to request a subsystem channel using the OpenChannel method of an SSH client connection. The extension request message sent to the server includes the name of the subsystem (in this case, "sftp") and a marshalled representation of the SubsystemRequest struct. The extension requests received from the server are handled in a separate goroutine.