4595ca4a5e
i have the program reaching out to the remote machine and creating the archive. however, it doesn't acutally grab the file and the program creates an empty archive.
51 lines
728 B
Go
51 lines
728 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/pkg/sftp"
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
var (
|
|
dstPath string = "/root/"
|
|
srcPath string = "/var/log/"
|
|
filename string = "dmesg"
|
|
)
|
|
|
|
func getFile(client *ssh.Client) {
|
|
t := time.Now()
|
|
sftp, err := sftp.NewClient(client)
|
|
|
|
if err != nil {
|
|
fmt.Errorf("FUCK")
|
|
}
|
|
|
|
defer sftp.Close()
|
|
|
|
srcFile, err := sftp.Open(srcPath + filename)
|
|
|
|
if err != nil {
|
|
fmt.Errorf("FUCK")
|
|
}
|
|
|
|
defer srcFile.Close()
|
|
|
|
timeResult := timeToString(t)
|
|
dstFile, err := os.Create(dstPath + filename + timeResult)
|
|
|
|
if err != nil {
|
|
fmt.Errorf("FUCK")
|
|
}
|
|
|
|
defer dstFile.Close()
|
|
|
|
srcFile.WriteTo(dstFile)
|
|
}
|
|
|
|
func timeToString(currentTime time.Time) string {
|
|
return currentTime.String()
|
|
}
|