dfbcce84ae
Now, you can add multiple logs within the configuration file, which is really cool, if you need multiple logs off of machines in one go round. Please note that you'll have to enter absolute paths for each log to get transferred.
48 lines
684 B
Go
48 lines
684 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/pkg/sftp"
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
func (s SSHConnection) getFile(client *ssh.Client) []*os.File {
|
|
homedir, _ := os.UserHomeDir()
|
|
var dstFiles []*os.File
|
|
|
|
for _, j := range s.Logs {
|
|
sftp, err := sftp.NewClient(client)
|
|
|
|
if err != nil {
|
|
fmt.Errorf("Error")
|
|
}
|
|
|
|
defer sftp.Close()
|
|
|
|
srcFile, err := sftp.Open(j)
|
|
|
|
if err != nil {
|
|
fmt.Errorf("Error")
|
|
}
|
|
|
|
defer srcFile.Close()
|
|
|
|
h := slashSeperator(j)
|
|
|
|
dstFile, err := os.Create(homedir + "/" + h)
|
|
|
|
if err != nil {
|
|
fmt.Errorf("Error")
|
|
}
|
|
|
|
defer dstFile.Close()
|
|
srcFile.WriteTo(dstFile)
|
|
|
|
dstFiles = append(dstFiles, dstFile)
|
|
}
|
|
|
|
return dstFiles
|
|
}
|