dutchcoders / dutchcoders/goftp

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

Open
#43 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
280
Forks
94
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.