diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-25 20:56:26 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-25 20:56:26 +0000 |
commit | 422eaae5fe0038ad189b8fd28cfd6a7094d67ae1 (patch) | |
tree | c68d6b2a9f5b82a23171b0a488a4b7e5c63ad860 /libgo/go/exp/ssh/doc.go | |
parent | e0f3ea3ed4b9d0bce9f4c14762e4257ba62c8fba (diff) | |
download | gcc-422eaae5fe0038ad189b8fd28cfd6a7094d67ae1.tar.gz |
libgo: Update to weekly.2012-01-15.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183539 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/exp/ssh/doc.go')
-rw-r--r-- | libgo/go/exp/ssh/doc.go | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/libgo/go/exp/ssh/doc.go b/libgo/go/exp/ssh/doc.go index 480f877191a..e7deb5ec168 100644 --- a/libgo/go/exp/ssh/doc.go +++ b/libgo/go/exp/ssh/doc.go @@ -14,7 +14,7 @@ others. An SSH server is represented by a ServerConfig, which holds certificate details and handles authentication of ServerConns. - config := new(ServerConfig) + config := new(ssh.ServerConfig) config.PubKeyCallback = pubKeyAuth config.PasswordCallback = passwordAuth @@ -34,8 +34,7 @@ Once a ServerConfig has been configured, connections can be accepted. if err != nil { panic("failed to accept incoming connection") } - err = sConn.Handshake(conn) - if err != nil { + if err := sConn.Handshake(conn); err != nil { panic("failed to handshake") } @@ -60,16 +59,20 @@ the case of a shell, the type is "session" and ServerShell may be used to present a simple terminal interface. if channel.ChannelType() != "session" { - c.Reject(UnknownChannelType, "unknown channel type") + channel.Reject(UnknownChannelType, "unknown channel type") return } channel.Accept() - shell := NewServerShell(channel, "> ") + term := terminal.NewTerminal(channel, "> ") + serverTerm := &ssh.ServerTerminal{ + Term: term, + Channel: channel, + } go func() { defer channel.Close() for { - line, err := shell.ReadLine() + line, err := serverTerm.ReadLine() if err != nil { break } @@ -78,8 +81,27 @@ present a simple terminal interface. return }() +To authenticate with the remote server you must pass at least one implementation of +ClientAuth via the Auth field in ClientConfig. + + // password implements the ClientPassword interface + type password string + + func (p password) Password(user string) (string, error) { + return string(p), nil + } + + config := &ssh.ClientConfig { + User: "username", + Auth: []ClientAuth { + // ClientAuthPassword wraps a ClientPassword implementation + // in a type that implements ClientAuth. + ClientAuthPassword(password("yourpassword")), + } + } + An SSH client is represented with a ClientConn. Currently only the "password" -authentication method is supported. +authentication method is supported. config := &ClientConfig{ User: "username", @@ -87,19 +109,19 @@ authentication method is supported. } client, err := Dial("yourserver.com:22", config) -Each ClientConn can support multiple interactive sessions, represented by a Session. +Each ClientConn can support multiple interactive sessions, represented by a Session. session, err := client.NewSession() -Once a Session is created, you can execute a single command on the remote side -using the Run method. +Once a Session is created, you can execute a single command on the remote side +using the Exec method. + b := bytes.NewBuffer() + session.Stdin = b if err := session.Run("/usr/bin/whoami"); err != nil { panic("Failed to exec: " + err.String()) } - reader := bufio.NewReader(session.Stdin) - line, _, _ := reader.ReadLine() - fmt.Println(line) + fmt.Println(bytes.String()) session.Close() */ package ssh |