add ftpActions

This commit is contained in:
dom 2020-07-18 08:55:51 +02:00
parent fb91452c46
commit ad10456a4a
1 changed files with 51 additions and 0 deletions

51
ftpActions.go Normal file
View File

@ -0,0 +1,51 @@
package paxan
import (
"io"
"os"
"time"
"github.com/jlaffaye/ftp"
)
func DownloadFTP(user string, password string, path string) error {
c, err := ftp.Dial("paxan-shop.de:21", ftp.DialWithTimeout(5*time.Second))
if err != nil {
return err
}
err = c.Login(user, password)
if err != nil {
return err
}
defer c.Quit()
//c.ChangeDir("desiredDir")
files, err := c.List("")
if err != nil {
return err
}
for _, file := range files {
res, err := c.Retr(file.Name)
if err != nil {
return err
}
defer res.Close()
outFile, err := os.Create(path.join(path, file.Name))
if err != nil {
return err
}
defer outFile.Close()
_, err = io.Copy(outFile, res)
if err != nil {
return err
}
}
return nil
}