How to use ftp.walk in goftp

68 views
Skip to first unread message

Nikhil Bhavsar

unread,
May 17, 2020, 1:19:35 PM5/17/20
to golang-nuts
Hi ,
I have to download files to local from remote using ftp
please suggest me if you have another option.
 // Download each file into local memory, and calculate it's sha256 hash
    err = ftp.Walk("/", func(path string, info os.FileMode, err error) error {
        _, err = ftp.Retr(path, func(r io.Reader) error {
            var hasher = sha256.New()
            if _, err = io.Copy(hasher, r); err != nil {
                return err
            }

            hash := fmt.Sprintf("%s %x", path, hex.EncodeToString(hasher.Sum(nil)))
            fmt.Println(hash)

            return err
        })

        return nil
    })
Reply all
Reply to author
Forward
0 new messages