From 72d2e670f1f57635bb54c09ed54d7b40d2320cb3 Mon Sep 17 00:00:00 2001 From: Stve Hb Date: Fri, 21 Feb 2025 00:15:28 +0100 Subject: [PATCH] Support ipv6 hostnames --- internal/provider/ssh/ssh_client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/provider/ssh/ssh_client.go b/internal/provider/ssh/ssh_client.go index 9e12e3a..19a45ca 100644 --- a/internal/provider/ssh/ssh_client.go +++ b/internal/provider/ssh/ssh_client.go @@ -4,8 +4,10 @@ import ( "context" "fmt" "io" + "net" "os" "path/filepath" + "strconv" "strings" "github.com/pkg/sftp" @@ -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)