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

no password #2

Open
undeadindustries opened this issue May 19, 2015 · 8 comments
Open

no password #2

undeadindustries opened this issue May 19, 2015 · 8 comments

Comments

@undeadindustries
Copy link

I can't seem to get this to work with anonymous as the username and an empty password.

if err = ftp.Login("anonymous", ""); err != nil {
panic(err)
}

it dies on ftp.Login

goroutine 1 [running]:
main.downloadDatabase()
ftp.go:30 +0x160
main.main()
init.go:7 +0x1b

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
exit status 2

@souravdatta
Copy link
Contributor

Yes, anonymous login does not work because by default the library tries to send the password even though login was successful with username only. Can you try the modifications I did with the pull request, or try it from my repository (souravdatta/goftp) and see if it still fails?

@nl5887
Copy link
Member

nl5887 commented May 19, 2015

Could you retry it with the latest version? I've merged the pull request from @souravdatta.

@undeadindustries
Copy link
Author

Thanks for the quick response!

I deleted the /usr/local/bin/pkg/darwin_amd64 folder and got goftp again, but it seems like I'm getting the same error.

You can test with ftp.musicbrainz.org:21

Thanks again!

@souravdatta
Copy link
Contributor

I tested with the latest merged copy of the code and found no problem in Connect. But Login() fails because of the long info message that comes as part of the Connect() call. The code handles this type of banners when it appears after the Login() (which is usually the case in sites like ftp.gnu.org). Does your panic message show lines like this?

panic: 220- F T P . O S U O S L . O R G
220- Oregon State University
220- Open Source Lab
220-
220- Un... etc.

If so, then I can reproduce it at my end. I think we need to modify the code to properly avoid such banner messages while checking for return status from connection.

@undeadindustries
Copy link
Author

That's exactly what's happening. Good call. Thanks!

2015/05/19 09:06:10 > USER anonymous
2015/05/19 09:06:10 < 220- F T P . O S U O S L . O R G
panic: 220- F T P . O S U O S L . O R G

goroutine 1 [running]:
main.downloadDatabase()
/ftp.go:30 +0x160
main.main()
init.go:7 +0x1b

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
exit status 2

@VincenzoLaSpesa
Copy link
Contributor

It's strange.
I can login manually with telnet:

    220-
    220-      Questions/Comments/Suggestions/Co
    220-
    220----------------------------------------
    220

    noop
    530 Please login with USER and PASS.
    user anonymous
    331 Please specify the password.
    pass anonymous
    230 Login successful.

But I can't get the same procedure working with the code!

func (ftp *FTP) SmartLogin(username string, password string) (err error) {
    var code int
    // Maybe the server has some useless words to say. Make him talk
    code, _ = ftp.RawCmd("NOOP")

    if code == 220 || code == 530 {
        // Maybe with another Noop the server will ask us to login?
        code, _ = ftp.RawCmd("NOOP")
        if code == 530 {
            // ok, let's login
            code, _ = ftp.RawCmd("USER %s", username)
            if code == 331 {
                // user accepted, password required
                code, _ = ftp.RawCmd("PASS %s", password)
                if code == 230 {
                    return
                }
            }
        }

    }
    // Nothing strange... let's try a normal login
    return ftp.Login(username, password)
}

func (ftp *FTP) RawCmd(command string, args ...interface{}) (code int, line string) {
    code = -1
    var err error
    if err = ftp.send(command, args...); err != nil {
        return code, ""
    }

    if line, err = ftp.receive(); err != nil {
        return code, ""
    }
    code, err = strconv.Atoi(line[:3])
    fmt.Println(code)
    return code, line
}   

My test server is ftp.musicbrainz.org

@VincenzoLaSpesa
Copy link
Contributor

Ok, I wrote a workaround.

https://github.com/VincenzoLaSpesa/goftp

@VincenzoLaSpesa
Copy link
Contributor

I think this issues can be closed with PR #4 (#4).
Can you confirm that?

zaz600 pushed a commit to zaz600/goftp that referenced this issue Jan 4, 2016
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

4 participants