Fix GetEntry / MLST for some servers - Fixes #321 (#322)

Some servers seem to send a blank line at the end of an MLST response.

    MLST Download
    250-
    Size=53248;Modify=20230327134339.000;Type=dir; Download

    250 Requested file action okay, completed.

Before this change this would cause the GetEntry method to return this
error.

    unsupported LIST line

This patch ignores blank lines in the MLST response.
This commit is contained in:
Nick Craig-Wood 2023-05-13 03:29:37 +01:00 committed by GitHub
parent 0feadd74ba
commit 36e873b513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -193,7 +193,7 @@ func (mock *ftpMock) listen() {
if cmdParts[1] == "multiline-dir" {
mock.printfLine("250-File data\r\n Type=dir;Size=0; multiline-dir\r\n Modify=20201213202400; multiline-dir\r\n250 End")
} else {
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n250 End")
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n \r\n250 End")
}
case "NLST":
if mock.dataConn == nil {

4
ftp.go
View File

@ -766,6 +766,10 @@ func (c *ServerConn) GetEntry(path string) (entry *Entry, err error) {
if len(l) > 0 && l[0] == ' ' {
l = l[1:]
}
// Some severs seem to send a blank line at the end which we ignore
if l == "" {
continue
}
if e, err = parseNextRFC3659ListLine(l, c.options.location, e); err != nil {
return nil, err
}