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

Login issue; Password gets a response code of "331 OK" #43

Open
BproB opened this issue Dec 12, 2018 · 0 comments
Open

Login issue; Password gets a response code of "331 OK" #43

BproB opened this issue Dec 12, 2018 · 0 comments

Comments

@BproB
Copy link

BproB commented Dec 12, 2018

Scenario: Connecting to an ftp server using a Proxy
Issue: Login fails intermittently
Error: Password gets a response of 331 OK

Output from the terminal:

2018/12/12 11:23:03 < 220 TEST Server
2018/12/12 11:23:03 220 TEST Server
2018/12/12 11:23:03 > USER test
2018/12/12 11:23:03 < 331 OK
2018/12/12 11:23:03 > PASS test
2018/12/12 11:23:03 < 331 OK

This all happens in a test file where I am creating an FTP server, and trying to connect to it through proxy. We are testing for a couple of scenarios; upload, download, and file stats. After a couple of successful runs, Login spits out the above error; wherein it expects some input from the user. I tried overcoming this by changing Login function this way:

func (ftp *FTP) Login(username string, password string) (err error) {
	if _, err = ftp.cmd("331", "USER %s", username); err != nil {
		if strings.HasPrefix(err.Error(), "230") {
			// Ok, probably anonymous server
			// but login was fine, so return no error
			err = nil
		} else {
			return
		}
	}
	if _, err = ftp.cmd("230", "PASS %s", password); err != nil {
		if strings.HasPrefix(err.Error(), "331") {
			// Ok, probably anonymous server
			// but login was fine, so return no error
			err = nil
		} else {
			return
		}
	}

	return
}

This ignores "331 OK" and moves forward. But when the test starts for Upload; after the first instruction upload function sends, it gets a response for the password: "230 Password ok, continue"

2018/12/12 11:23:03 < 220 TEST Server
2018/12/12 11:23:03 220 TEST Server

2018/12/12 11:23:03 > USER test
2018/12/12 11:23:03 < 331 OK
2018/12/12 11:23:03 > PASS test
2018/12/12 11:23:03 < 331 OK

=== RUN   TestUpload
In TestUpload()
2018/12/12 11:23:03 > TYPE I
2018/12/12 11:23:03 < **230 Password ok, continue**
2018/12/12 11:23:03 > STAT sample_for_ftp.txt
2018/12/12 11:23:03 < 200 Type set to binary
x
Failures:

The hacky fix that I came up with to overcome this issue was to re-login to the ftp server during the setup but I need to understand why this is happening as it is weird, and defies the underlying ftp concepts.

Please help/explain.

@BproB BproB changed the title Login issue; Password get a response code of "331 OK" Login issue; Password gets a response code of "331 OK" Dec 12, 2018
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

1 participant