goftp
goftp copied to clipboard
no password
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
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?
Could you retry it with the latest version? I've merged the pull request from @souravdatta.
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!
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.
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
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
Ok, I wrote a workaround.
https://github.com/VincenzoLaSpesa/goftp
I think this issues can be closed with PR #4 (https://github.com/dutchcoders/goftp/pull/4). Can you confirm that?