Skip to content

Commit

Permalink
Merge pull request #13 from sz-po/feat/dial-with-connection
Browse files Browse the repository at this point in the history
feat: added DialWithConnection function
  • Loading branch information
helloyi authored Apr 26, 2024
2 parents d5a9f15 + b4e6323 commit 334a88f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sshclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error) {
return &Client{sshClient: sshClient}, 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 {
merr := newMultiError()
Expand Down

0 comments on commit 334a88f

Please sign in to comment.