Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

229 Entering Extended Passive Mode (|||45368|) when attempting to read the file repeatedly after creating a connection only once. Report an error #369

Open
chenpb-lu opened this issue Apr 10, 2024 · 2 comments

Comments

@chenpb-lu
Copy link

func t(filePath string) {
	c, err := ftp.Dial(ftpServer, ftp.DialWithTimeout(5*time.Second))
	if err != nil {
		log.Fatal(fmt.Sprintf("filePath: %s err: %v", filePath, err))
	}

	err = c.Login(ftpUser, ftpPasswd)
	if err != nil {
		log.Fatal(fmt.Sprintf("filePath: %s err: %v", filePath, err))
	}

	for i := 0; i < 5; i++ {
		_, err := c.Retr(filePath)
		if err != nil {
			log.Fatal(fmt.Sprintf("filePath: %s err: %v", filePath, err))
		}
	}
	if err := c.Quit(); err != nil {
		log.Fatal(err)
	}
}
@chenpb-lu
Copy link
Author

The package version is github.com/jlaffaye/ftp v0.2.0

@wolveix
Copy link

wolveix commented Apr 26, 2024

It's because you're not closing the file. Try this:

func t(filePath string) {
	conn, err := ftp.Dial(ftpServer, ftp.DialWithTimeout(5*time.Second))
	if err != nil {
		log.Fatal(fmt.Sprintf("filePath: %s err: %v", filePath, err))
	}

	if err = conn.Login(ftpUser, ftpPasswd); err != nil {
		log.Fatal(fmt.Sprintf("filePath: %s err: %v", filePath, err))
	}

	for i := 0; i < 5; i++ {
		// pull file
		resp, err := conn.Retr(filePath)
		if err != nil {
			log.Fatal(fmt.Sprintf("filePath: %s err: %v", filePath, err))
		}

		// do something with the file

		// close the file
		if err = resp.Close(); err != nil {
			log.Fatal(err)
		}
	}

	if err = conn.Quit(); err != nil {
		log.Fatal(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants