diff --git a/README.md b/README.md index 7fa8768..08dafc7 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ func main() { log.Fatal(err) } + // Make a ssh connection to 22 port by default. client, err := goph.New("root", "192.1.1.3", auth) if err != nil { log.Fatal(err) @@ -80,6 +81,12 @@ func main() { } ``` +#### Start Connection With Custom Port: +```go +client, err := goph.New("root", "192.1.1.3:8998", auth) +``` + + #### 🔐 Start Connection With Protected Private Key: ```go auth, err := goph.Key("/home/mohamed/.ssh/id_rsa", "you_passphrase_here") diff --git a/client.go b/client.go index 0e4267c..876f8a5 100644 --- a/client.go +++ b/client.go @@ -9,6 +9,7 @@ import ( "io" "net" "os" + "strconv" "time" "github.com/pkg/sftp" @@ -43,10 +44,23 @@ func New(user string, addr string, auth Auth) (c *Client, err error) { return } + host, port_str, err := net.SplitHostPort(addr) + if err != nil { + return + } + if len(port_str) == 0 { + port_str = "22" + } + port_int, err := strconv.Atoi(port_str) + if err != nil { + return + } + port := uint(port_int) + c, err = NewConn(&Config{ User: user, - Addr: addr, - Port: 22, + Addr: host, + Port: port, Auth: auth, Timeout: DefaultTimeout, Callback: callback,