Example #1
0
func (s *S3) Download(remote_path, local_path string, uid, gid int, perms, listener string) error {
	log.Infof("S3 Downloading %s", local_path)
	conf, keys := s.GetS3Config()

	// Open bucket to put file into
	s3 := s3gof3r.New("", *keys)
	b := s3.Bucket(s.config.Listeners[s.listener].Bucket)

	r, _, err := b.GetReader(remote_path, conf)
	if err != nil {
		return err
	}
	// stream to file
	if _, err = utils.FileWrite(local_path, r, uid, gid, perms); err != nil {
		return err
	}
	err = r.Close()
	if err != nil {
		return err
	}
	basePath := s.config.Listeners[listener].BasePath
	datastore.UpdateHost(listener, strings.TrimLeft(local_path, basePath))

	return err
}
Example #2
0
func GetNodeCopy(item utils.DataTable, listener string, uid, gid int, perms string) bool {
	cfg := utils.GetConfig()
	aliveNodes := nodeinfo.GetNodes()
	for _, node := range aliveNodes {
		log.Infof("Trying download from: %s", node.NodeIPs)
		nIPs := strings.Split(node.NodeIPs, ",")
		for _, ipAddress := range nIPs {
			resp, err := getData(ipAddress, cfg.ServerConfig.ListenPort, listener, utils.GetRelativePath(listener, item.Path))
			if err == nil {
				defer resp.Body.Close()
				if resp.Status == "404" {
					log.Infof("File not found: %s", item.Path)
					return false
				}
				size, err := utils.FileWrite(item.Path, resp.Body, uid, gid, perms)
				if err != nil {
					log.Infof("Cannot write file: %s", item.Path)
					return false
				} else {
					log.Infof("%s with %v bytes downloaded", item.Path, size)
					return true
				}
				return false
			} else {
				return false
			}
		}
	}
	return false
}