Skip to content

Commit

Permalink
Fix GetEntry / MLST for servers which send multiple spaces
Browse files Browse the repository at this point in the history
Some servers seem to send multiple spaces at the end of an MLST response.

    MLST Workspace
    250-Listing Workspace
      size=0;type=dir;perm=rwx;modify=20250218125218; /Workspace
    250 End

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

    unsupported LIST line

This patch ignores zero or more spaces at the start of the MLST response.
  • Loading branch information
ncw committed Feb 19, 2025
1 parent 2455144 commit 1fa62b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\n \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 {
Expand Down
6 changes: 3 additions & 3 deletions ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ func (c *ServerConn) GetEntry(path string) (entry *Entry, err error) {
e := &Entry{}
for _, l := range lines[1 : lc-1] {
// According to RFC 3659, the entry lines must start with a space when passed over the
// control connection. Some servers don't seem to add that space though. Both forms are
// accepted here.
if len(l) > 0 && l[0] == ' ' {
// control connection. Some servers don't seem to add that space though and some servers
// add multiple spaces. All forms are accepted here.
for len(l) > 0 && l[0] == ' ' {
l = l[1:]
}
// Some severs seem to send a blank line at the end which we ignore
Expand Down

0 comments on commit 1fa62b3

Please sign in to comment.