Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
18 changes: 16 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net"
"os"
"strconv"
"time"

"github.com/pkg/sftp"
Expand Down Expand Up @@ -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,
Expand Down