Fix ssh identityfile

This commit is contained in:
2024-12-07 19:44:57 +01:00
parent 793b04340e
commit 085bdf468f
5 changed files with 12 additions and 11 deletions

View File

@@ -56,7 +56,7 @@ if err != nil {
```go ```go
sshStorage, err := ssh.NewStorage(ssh.Config{ sshStorage, err := ssh.NewStorage(ssh.Config{
Host: "", Host: "",
Port: "", Port: 22,
User: "", User: "",
Password: "", Password: "",
RemotePath: "", RemotePath: "",
@@ -80,7 +80,7 @@ log.Fatalf("Error copying file, error %v", err)
```go ```go
ftpStorage, err := ftp.NewStorage(ftp.Config{ ftpStorage, err := ftp.NewStorage(ftp.Config{
Host: "", Host: "",
Port: "", Port: 22,
User: "", User: "",
Password: "", Password: "",
RemotePath: "", RemotePath: "",

View File

@@ -44,14 +44,14 @@ type Config struct {
Host string Host string
User string User string
Password string Password string
Port string Port int
LocalPath string LocalPath string
RemotePath string RemotePath string
} }
// createClient creates FTP Client // createClient creates FTP Client
func createClient(conf Config) (*ftp.ServerConn, error) { func createClient(conf Config) (*ftp.ServerConn, error) {
ftpClient, err := ftp.Dial(fmt.Sprintf("%s:%s", conf.Host, conf.Port), ftp.DialWithTimeout(5*time.Second)) ftpClient, err := ftp.Dial(fmt.Sprintf("%s:%d", conf.Host, conf.Port), ftp.DialWithTimeout(5*time.Second))
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to connect to FTP: %w", err) return nil, fmt.Errorf("failed to connect to FTP: %w", err)
} }

View File

@@ -178,16 +178,16 @@ func (s s3Storage) Prune(retentionDays int) error {
Key: object.Key, Key: object.Key,
}) })
if err != nil { if err != nil {
fmt.Printf("failed to delete object %s: %v", *object.Key, err) fmt.Printf("failed to delete object %s: %v\n", *object.Key, err)
} else { } else {
fmt.Printf("Deleted object %s", *object.Key) fmt.Printf("Deleted object %s\n", *object.Key)
} }
} }
} }
return !lastPage return !lastPage
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to list objects: %v", err) return fmt.Errorf("failed to list objects: %v\n", err)
} }
return nil return nil

View File

@@ -46,7 +46,7 @@ type Config struct {
Host string Host string
User string User string
Password string Password string
Port string Port int
IdentifyFile string IdentifyFile string
LocalPath string LocalPath string
RemotePath string RemotePath string
@@ -54,15 +54,15 @@ type Config struct {
// createClient creates SSH Client // createClient creates SSH Client
func createClient(conf Config) (scp.Client, error) { func createClient(conf Config) (scp.Client, error) {
if _, err := os.Stat(conf.IdentifyFile); os.IsNotExist(err) { if _, err := os.Stat(conf.IdentifyFile); !os.IsNotExist(err) {
clientConfig, err := auth.PrivateKey(conf.User, conf.IdentifyFile, ssh.InsecureIgnoreHostKey()) clientConfig, err := auth.PrivateKey(conf.User, conf.IdentifyFile, ssh.InsecureIgnoreHostKey())
return scp.NewClient(fmt.Sprintf("%s:%s", conf.Host, conf.Port), &clientConfig), err return scp.NewClient(fmt.Sprintf("%s:%d", conf.Host, conf.Port), &clientConfig), err
} else { } else {
if conf.Password == "" { if conf.Password == "" {
return scp.Client{}, errors.New("ssh password required") return scp.Client{}, errors.New("ssh password required")
} }
clientConfig, err := auth.PasswordKey(conf.User, conf.Password, ssh.InsecureIgnoreHostKey()) clientConfig, err := auth.PasswordKey(conf.User, conf.Password, ssh.InsecureIgnoreHostKey())
return scp.NewClient(fmt.Sprintf("%s:%s", conf.Host, conf.Port), &clientConfig), err return scp.NewClient(fmt.Sprintf("%s:%d", conf.Host, conf.Port), &clientConfig), err
} }
} }

1
pkg/ssh/ssh_test.go Normal file
View File

@@ -0,0 +1 @@
package ssh