mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-06 17:58:30 +08:00
parent
030ab743f3
commit
4ebd4bddee
6 changed files with 14 additions and 18 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
|
|
@ -53,11 +52,12 @@ func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
|
|||
return nil
|
||||
},
|
||||
}
|
||||
if _, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", address, port), clientConfig); err != nil {
|
||||
addr := net.JoinHostPort(address, port)
|
||||
if _, err := ssh.Dial("tcp", addr, clientConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sftpClient{connInfo: fmt.Sprintf("%s:%s", address, port), config: clientConfig}, nil
|
||||
return &sftpClient{connInfo: addr, config: clientConfig}, nil
|
||||
}
|
||||
|
||||
func (s sftpClient) Upload(src, target string) (bool, error) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package client
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -25,7 +25,7 @@ func NewWebDAVClient(vars map[string]interface{}) (*webDAVClient, error) {
|
|||
username := loadParamFromVars("username", vars)
|
||||
bucket := loadParamFromVars("bucket", vars)
|
||||
|
||||
url := fmt.Sprintf("%s:%s", address, port)
|
||||
url := net.JoinHostPort(address, port)
|
||||
if len(port) == 0 {
|
||||
url = address
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ssh
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -24,12 +25,10 @@ type SSHClient struct {
|
|||
}
|
||||
|
||||
func NewClient(c ConnInfo) (*SSHClient, error) {
|
||||
if strings.Contains(c.Addr, ":") {
|
||||
c.Addr = fmt.Sprintf("[%s]", c.Addr)
|
||||
}
|
||||
config := &gossh.ClientConfig{}
|
||||
config.SetDefaults()
|
||||
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
|
||||
|
||||
addr := net.JoinHostPort(c.Addr, fmt.Sprintf("%d", c.Port))
|
||||
config.User = c.User
|
||||
if c.AuthMode == "password" {
|
||||
config.Auth = []gossh.AuthMethod{gossh.Password(c.Password)}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
|
|
@ -56,11 +55,12 @@ func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
|
|||
return nil
|
||||
},
|
||||
}
|
||||
if _, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", address, port), clientConfig); err != nil {
|
||||
addr := net.JoinHostPort(address, port)
|
||||
if _, err := ssh.Dial("tcp", addr, clientConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sftpClient{connInfo: fmt.Sprintf("%s:%s", address, port), config: clientConfig, bucket: bucket}, nil
|
||||
return &sftpClient{connInfo: addr, config: clientConfig, bucket: bucket}, nil
|
||||
}
|
||||
|
||||
func (s sftpClient) Upload(src, target string) (bool, error) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -25,7 +25,7 @@ func NewWebDAVClient(vars map[string]interface{}) (*webDAVClient, error) {
|
|||
username := loadParamFromVars("username", vars)
|
||||
bucket := loadParamFromVars("bucket", vars)
|
||||
|
||||
url := fmt.Sprintf("%s:%s", address, port)
|
||||
url := net.JoinHostPort(address, port)
|
||||
if len(port) == 0 {
|
||||
url = address
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,9 @@ type SSHClient struct {
|
|||
}
|
||||
|
||||
func NewClient(c ConnInfo) (*SSHClient, error) {
|
||||
if strings.Contains(c.Addr, ":") {
|
||||
c.Addr = fmt.Sprintf("[%s]", c.Addr)
|
||||
}
|
||||
config := &gossh.ClientConfig{}
|
||||
config.SetDefaults()
|
||||
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
|
||||
addr := net.JoinHostPort(c.Addr, fmt.Sprintf("%d", c.Port))
|
||||
config.User = c.User
|
||||
if c.AuthMode == "password" {
|
||||
config.Auth = []gossh.AuthMethod{gossh.Password(c.Password)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue