Example #1
0
// Dial connects to the ardrone ftp server at addr. The ftpHome must be set
// to the ftp home directory.
func Dial(addr string, ftpHome string) (*Conn, error) {
	ftpConn, err := goftp.Connect(addr)
	if err != nil {
		return nil, err
	}
	return &Conn{conn: ftpConn, ftpHome: ftpHome}, nil
}
Example #2
0
func (n *ftpFetcher) Fetch(resource string) error {
	n.data = GetCachedFile(resource)
	if n.data != nil {
		return nil
	}

	furl, err := url.Parse(resource)
	if err != nil {
		return err
	}

	if !strings.Contains(furl.Host, ":") {
		furl.Host = furl.Host + ":21"
	}
	ftp, err := goftp.Connect(furl.Host)
	if err != nil {
		return err
	}
	defer ftp.Quit()

	fusername := "******"
	fpassword := "******"

	if furl.User != nil {
		passwd, haspass := furl.User.Password()
		if haspass {
			fpassword = passwd
		}
		fusername = furl.User.Username()
	}

	err = ftp.Login(fusername, fpassword)
	if err != nil {
		return err
	}
	defer ftp.Logout()

	resp, err := ftp.Retr(furl.Path)
	if err != nil {
		return err
	}

	n.data, err = ioutil.ReadAll(resp)
	resp.Close()

	PutCachedFile(resource, n.data)
	return err
}