From b4e63232f8098cd68f8947b09187d5752e549b83 Mon Sep 17 00:00:00 2001 From: Szymon Podeszwa <2962046+sz-po@users.noreply.github.com> Date: Fri, 10 Jun 2022 16:49:40 +0200 Subject: [PATCH] added DialWithConnection function --- sshclient.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sshclient.go b/sshclient.go index 0c48160..49561b9 100644 --- a/sshclient.go +++ b/sshclient.go @@ -101,6 +101,20 @@ func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error) { }, nil } +// DialWithConnection starts a client connection using existing net.Conn. +func DialWithConnection(conn net.Conn, addr string, config *ssh.ClientConfig) (*Client, error) { + ncc, chans, reqs, err := ssh.NewClientConn(conn, addr, config) + if err != nil { + return nil, err + } + + client := ssh.NewClient(ncc, chans, reqs) + + return &Client{ + client: client, + }, nil +} + // Close closes the underlying client network connection. func (c *Client) Close() error { return c.client.Close()