Exemple #1
0
func transfer(dst_name string, src io.Reader) error {

	config := goftp.Config{
		User:               username,
		Password:           password,
		ConnectionsPerHost: 10,
		Timeout:            10 * time.Second,
		Logger:             nil,
	}

	fmt.Printf("Dialing into %s... ", host)
	client, err := goftp.DialConfig(config, host)
	if err != nil {
		return err
	}
	fmt.Println("done.")

	fmt.Printf("Writing to file %s... ", dst_name)
	err = client.Store(dst_name, src)
	if err != nil {
		return err
	}
	fmt.Println("done.")
	return nil
}
Exemple #2
0
func main() {
	config := goftp.Config{
		User:            "******",
		Password:        "******",
		ActiveTransfers: true, // 如果服务器不是主动模式可以不设置
	}
	ftpConn, err := goftp.DialConfig(config, "10.10.3.100")
	checkError(err)
	defer ftpConn.Close()

	// 下载
	readme, err := os.Create("readme")
	checkError(err)
	defer readme.Close()

	err = ftpConn.Retrieve("test/README", readme)
	checkError(err)

	// 上传
	uploadFile, err := os.Open("main.go")
	checkError(err)
	defer uploadFile.Close()

	err = ftpConn.Store("codyguo/main.go", uploadFile)
	checkError(err)
}
Exemple #3
0
func main() {
	config := goftp.Config{
		User:            "******",
		Password:        "******",
		ActiveTransfers: true, // 如果服务器不是主动模式可以不设置
	}
	ftpConn, err := goftp.DialConfig(config, "10.10.2.222")
	checkError(err)
	defer ftpConn.Close()

	// 下载
	readme, err := os.Create("eth2.cap")
	checkError(err)
	defer readme.Close()

	err = ftpConn.Retrieve("eth2.cap", readme)
	checkError(err)

	// 上传
	uploadFile, err := os.Open("main.go")
	checkError(err)
	defer uploadFile.Close()

	err = ftpConn.Store("main.go", uploadFile)
	checkError(err)
}
func uploadObjects(info *SyncInfo, objects *[]string) {
	ftpConfig := goftp.Config{
		User:               config.FtpUser,
		Password:           config.FtpPassword,
		ConnectionsPerHost: 10,
	}
	ftpClient, err := goftp.DialConfig(ftpConfig, config.FtpAddr)

	if err != nil {
		log.Fatalln("ftp connect failed. ", err)
	}

	//create dir
	makeDir(info, ftpClient, objects)

	doUpload := make(chan bool)
	uploadDone := make(chan bool)
	go func() {
		for {
			_, ok := <-uploadDone
			if ok {
				currentFtpConnect--
			} else {
				return
			}
		}
	}()

	// create upload job
	for _, obj := range *objects {
		go doUploadObject(info, obj, ftpClient, doUpload, uploadDone)
	}

	// send doUpload access
	for i := 0; i < len(*objects); i++ {
		for currentFtpConnect >= MaxFtpConnect {
			time.Sleep(time.Millisecond * 500)
		}
		doUpload <- true
		currentFtpConnect++
	}

	for currentFtpConnect > 0 {
		log.Println("currentFtpConnect: ", currentFtpConnect)
		time.Sleep(time.Millisecond * 500)
	}
}
Exemple #5
0
func (f *FTP) Upload(fullfile, fileName string) error {
	config := goftp.Config{
		User:            f.user,
		Password:        f.passwd,
		ActiveTransfers: false, // 如果服务器不是主动模式可以不设置
	}
	ftpConn, err := goftp.DialConfig(config, f.ip)
	if err != nil {
		return err
	}
	defer ftpConn.Close()

	// 上传
	uploadFile, err := os.Open(fullfile)
	if err != nil {
		return err
	}
	defer uploadFile.Close()

	return ftpConn.Store(fileName, uploadFile)
}