diff --git a/README.md b/README.md index 311bd42..803eb52 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Password for login (default "123456") -gpgkey path File of the public GPG key to encrypt files to + -output + Path to directory to write encrypted files to ``` diff --git a/main.go b/main.go index c0e7cdb..e2191d5 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io" "os" "path" + "path/filepath" "strings" "time" "flag" @@ -16,6 +17,7 @@ import ( type ForwarderDriver struct { RecipientKey *crypto.Key + OutputPath string server.Perm } @@ -107,10 +109,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa t := time.Now() encrypted_filename := fmt.Sprintf("scan_%04d-%02d-%02d-%02d-%02d_%v.asc", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), dest_filename) - log.Printf("Writing to %v", encrypted_filename) + encrypted_file_path := filepath.Join(driver.OutputPath, encrypted_filename) + + log.Printf("Writing to %v", encrypted_file_path) log.Printf("Opening output file") - encryptedFile, err := os.Create(encrypted_filename) + encryptedFile, err := os.Create(encrypted_file_path) if err != nil { log.Printf("Error: %v", err) return 0, err @@ -147,11 +151,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa type ForwarderDriverFactory struct { RecipientKey *crypto.Key + OutputPath string server.Perm } func (factory *ForwarderDriverFactory) NewDriver() (server.Driver, error) { - return &ForwarderDriver{factory.RecipientKey, factory.Perm}, nil + return &ForwarderDriver{factory.RecipientKey, factory.OutputPath, factory.Perm}, nil } @@ -164,8 +169,17 @@ func main() { host = flag.String("host", "localhost", "Host") passiveports = flag.String("passiveports", "2130-2134", "Passive ports") gpgkey_path = flag.String("gpgkey", "", "File of the public GPG key to encrypt files to") + output_path = flag.String("output", ".", "Path to directory to write encrypted files to") ) flag.Parse() + + absolute_output_path, err := filepath.Abs(*output_path) + if err != nil { + log.Fatalf("Error: %v", err) + } + + log.Printf("Writing encrypted files to %v", absolute_output_path) + if *gpgkey_path == "" { log.Fatalf("Specify path to GPG key with -gpgkey") } @@ -190,6 +204,7 @@ func main() { factory := &ForwarderDriverFactory{ RecipientKey: gpgkey, + OutputPath: absolute_output_path, Perm: server.NewSimplePerm("user","group"), }