Skip to content

Commit 1fa62b3

Browse files
committed
Fix GetEntry / MLST for servers which send multiple spaces
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.
1 parent 2455144 commit 1fa62b3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

conn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (mock *ftpMock) listen() {
193193
if cmdParts[1] == "multiline-dir" {
194194
mock.printfLine("250-File data\r\n Type=dir;Size=0; multiline-dir\r\n Modify=20201213202400; multiline-dir\r\n250 End")
195195
} else {
196-
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n \r\n250 End")
196+
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n \r\n250 End")
197197
}
198198
case "NLST":
199199
if mock.dataConn == nil {

ftp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,9 @@ func (c *ServerConn) GetEntry(path string) (entry *Entry, err error) {
778778
e := &Entry{}
779779
for _, l := range lines[1 : lc-1] {
780780
// According to RFC 3659, the entry lines must start with a space when passed over the
781-
// control connection. Some servers don't seem to add that space though. Both forms are
782-
// accepted here.
783-
if len(l) > 0 && l[0] == ' ' {
781+
// control connection. Some servers don't seem to add that space though and some servers
782+
// add multiple spaces. All forms are accepted here.
783+
for len(l) > 0 && l[0] == ' ' {
784784
l = l[1:]
785785
}
786786
// Some severs seem to send a blank line at the end which we ignore

0 commit comments

Comments
 (0)