Skip to content

Commit

Permalink
fmt and fix for ipv6.
Browse files Browse the repository at this point in the history
  • Loading branch information
melbahja committed Oct 22, 2020
1 parent 8b4aa56 commit 170b631
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ package goph
import (
"fmt"
"io"
"net"
"os"
"time"

"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)

// A Client represents Goph client.
// Client represents Goph client.
type Client struct {
*ssh.Client
Config *Config
Expand All @@ -30,7 +31,7 @@ type Config struct {
Callback ssh.HostKeyCallback
}

// DefaultTimeout represents connection timeout.
// DefaultTimeout is the timeout of ssh client connection.
var DefaultTimeout = 20 * time.Second

// New starts a new ssh connection, the host public key must be in known hosts.
Expand Down Expand Up @@ -81,15 +82,15 @@ func NewConn(config *Config) (c *Client, err error) {

// Dial starts a client connection to SSH server based on config.
func Dial(proto string, c *Config) (*ssh.Client, error) {
return ssh.Dial(proto, fmt.Sprintf("%s:%d", c.Addr, c.Port), &ssh.ClientConfig{
return ssh.Dial(proto, net.JoinHostPort(c.Addr, fmt.Sprint(c.Port)), &ssh.ClientConfig{
User: c.User,
Auth: c.Auth,
Timeout: c.Timeout,
HostKeyCallback: c.Callback,
})
}

// Run runs a command over client connection.
// Run starts a new SSH session and runs the cmd, it returns CombinedOutput and err if any.
func (c Client) Run(cmd string) ([]byte, error) {

var (
Expand Down

0 comments on commit 170b631

Please sign in to comment.