1

I'm using the code below to iterate through a folder (unzipping .zip files locally, performing actions on them etc).

func extractZipWithPassword(localPath string, pathToServer string) {
    filepath.Walk(localPath, func(path string, info os.FileInfo, err error) error {
        extension := filepath.Ext(path)
        fileName := filepath.Base(path)
        if extension == ".zip" {
            zip_password := "password"
            outDirZIP := filepath.Dir(path) + "/" + strings.TrimSuffix(fileName, extension)
            os.Mkdir(outDirZIP, 0777)
            commandString := fmt.Sprintf(`unzip -P %s %s -d %s`, zip_password, path, outDirZIP)
            commandSlice := strings.Fields(commandString)
            fmt.Println(commandString)
            c := exec.Command(commandSlice[0], commandSlice[1:]...)
            c.Run()
            zipCount++
            iterateThroughPE(outDirZIP)
            parsePKCS7(outDirZIP)
            splitter(start_string, end_string, outDirZIP)
            return nil
        } else {
            fmt.Println("")
            return nil
        }
    })
}

However now I need to extract archives from an SMB folder that requires login+password combination to access. I tried using this lib github.com/hirochachacha/go-smb2 to access the shared folder, but to no success. Is there a way to straight up unzip .zip files to a local folder of my choice with Go? If there's not, what are my options?

UPDATE

Got the share mounted with go-smb2, not sure how to proceed next.

func listShares(path string) {
    conn, err := net.Dial("tcp", "ip:port")
    if err != nil {
        panic(err)
    }
    defer conn.Close()

    d := &smb2.Dialer{
        Initiator: &smb2.NTLMInitiator{
            User:     "user",
            Password: "pw",
        },
    }

    s, err := d.Dial(conn)
    if err != nil {
        panic(err)
    }
    defer s.Logoff()

    names, err := s.ListSharenames()
    if err != nil {
        panic(err)
    }

    for _, name := range names {
        fmt.Println(name)
    }
    fs, err := s.Mount("sharename")
    if err != nil {
        panic(err)
    }
    defer fs.Umount()
    
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.