Skip to content

Commit

Permalink
Support ipv6 hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-hb committed Feb 20, 2025
1 parent 4a3d543 commit 72d2e67
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/provider/ssh/ssh_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"
"io"
"net"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/sftp"
Expand Down Expand Up @@ -80,7 +82,15 @@ func NewSSHClient(ctx context.Context, config SSHConfig) (*SSHClient, error) {
HostKeyCallback: ssh.InsecureIgnoreHostKey(), // TODO: Allow configuring host key verification
}

client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", config.Host, config.Port), sshConfig)
host := config.Host
isIpv6 := net.ParseIP(config.Host).To16() == nil
if isIpv6 {
host = fmt.Sprintf("[%s]", config.Host)
}

host += strconv.Itoa(config.Port)

client, err := ssh.Dial("tcp", host, sshConfig)
if err != nil {
logger.WithContext(ctx).WithError(err).Error("Failed to connect to SSH server")
return nil, fmt.Errorf("failed to connect to SSH server: %w", err)
Expand Down

0 comments on commit 72d2e67

Please sign in to comment.