Ejemplo n.º 1
0
// it's alive!
func main() {
	factory := &MemDriverFactory{}
	ftpServer := graval.NewFTPServer(&graval.FTPServerOpts{Factory: factory})
	err := ftpServer.ListenAndServe()
	if err != nil {
		log.Print(err)
		log.Fatal("Error starting server!")
	}
}
Ejemplo n.º 2
0
// it's alive!
func main() {
	cacheDir := os.Getenv("FTP2S3_CACHE_DIR")
	if cacheDir == "" {
		fmt.Println("Set FTP2S3_CACHE_DIR")
		os.Exit(1)
	}

	bucket := os.Getenv("FTP2S3_BUCKET")
	if bucket == "" {
		fmt.Println("Set FTP2S3_BUCKET")
		os.Exit(1)
	}

	prefix := os.Getenv("FTP2S3_PREFIX")
	if prefix == "" {
		fmt.Println("Set FTP2S3_PREFIX to the prefix you want to store in on S3")
		os.Exit(1)
	}

	username := os.Getenv("FTP2S3_USERNAME")
	if username == "" {
		fmt.Println("Set FTP2S3_USERNAME")
		os.Exit(1)
	}

	password := os.Getenv("FTP2S3_PASSWORD")
	if password == "" {
		fmt.Println("Set FTP2S3_PASSWORD")
		os.Exit(1)
	}

	region := os.Getenv("FTP2S3_REGION")
	if region == "" {
		region = "us-east-1"
	}

	port := os.Getenv("FTP2S3_PORT")
	if port == "" {
		port = "2121"
	}

	portInt, err := strconv.Atoi(port)
	if err != nil {
		log.Fatal("Port must be numeric ", err)
	}

	fileQueue := make(chan string, 10000)

	sess := session.New(&aws.Config{Region: aws.String(region)})
	svc := s3.New(sess)

	uploader := &S3Uploader{
		S3:       svc,
		CacheDir: cacheDir,
		S3Bucket: bucket,
		S3Prefix: prefix,
	}

	go uploader.UploadLoop(fileQueue)

	go func() {
		uploader.Reconcile()
		time.Sleep(30 * time.Minute)
	}()

	factory := &S3DriverFactory{
		CacheDir:    cacheDir,
		UploadQueue: fileQueue,
		Username:    username,
		Password:    password,
	}

	ftpServer := graval.NewFTPServer(&graval.FTPServerOpts{
		Factory: factory,
		//Hostname: "0.0.0.0",
		Port: portInt,
	})
	err = ftpServer.ListenAndServe()
	if err != nil {
		log.Print(err)
		log.Fatal("Error starting server!")
	}
}