예제 #1
1
func GetFolders(ftp *goftp.FTP, path string) []string {
	var err error
	var filesAndFolders []string
	if filesAndFolders, err = ftp.List(path); err != nil {
		panic(err)
	}

	var folders = make([]string, 0)
	for i := 0; i < len(filesAndFolders); i++ {
		var file string = filesAndFolders[i]
		if strings.ContainsAny(file, "type=dir") {
			folders = append(folders, file)
		}
	}
	return folders
}
예제 #2
0
파일: logdl.go 프로젝트: JamieSinn/scripts
func downloadDirectory(directory string, ftp *goftp.FTP) {
	var files []string
	var err error
	if files, err = ftp.List(""); err != nil {
		panic(err)
	}
	directory = strings.Replace(directory, "\r\n", "", -1)

	for f := range files {
		filename := strings.Split(files[f], "; ")
		newPath := directory + "/" + filename[1]
		if !strings.Contains(filename[0], "type=dir;") {
			downloadFile(newPath, ftp)
		} else {
			ftp.Cwd(newPath)
			downloadDirectory(newPath, ftp)
		}
	}
}
예제 #3
0
func main() {
	var err error
	var ftp *goftp.FTP

	// For debug messages: goftp.ConnectDbg("ftp.server.com:21")
	if ftp, err = goftp.Connect("172.8.4.101:21"); err != nil {
		panic(err)
	}

	defer ftp.Close()

//	config := tls.Config{
//		InsecureSkipVerify: true,
//		ClientAuth:         tls.RequestClientCert,
//	}
//
//	if err = ftp.AuthTLS(config); err != nil {
//		panic(err)
//	}

	if err = ftp.Login("bob", "p@ssw0rd"); err != nil {
		panic(err)
	}

	if err = ftp.Cwd("/home/bob"); err != nil {
		panic(err)
	}

	var curpath string
	if curpath, err = ftp.Pwd(); err != nil {
		panic(err)
	}

	fmt.Printf("Current path: %s\n", curpath)

	var files []string
	if files, err = ftp.List(""); err != nil {
		panic(err)
	}

	fmt.Println(files)

//	var file *os.File
//	if file, err = os.Open("/tmp/test.txt"); err != nil {
//		panic(err)
//	}
//
//	if err := ftp.Stor("/test.txt", file); err != nil {
//		panic(err)
//	}

	err = ftp.Walk("/home/bob", 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, sha256.Sum256(nil))
			fmt.Println(hash)

			return err
		})

		return nil
	})

	fmt.Println(err)
}