diff --git a/go.mod b/go.mod index 027c353..f533546 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rclone/ftp +module github.com/chi-deutschland/ftp go 1.14 diff --git a/parse.go b/parse.go index dbe0324..9c02280 100644 --- a/parse.go +++ b/parse.go @@ -71,6 +71,11 @@ func parseRFC3659ListLine(line string, now time.Time, loc *time.Location) (*Entr return e, nil } +func isNumber(str string) bool { + _, err := strconv.ParseUint(str, 0, 64) + return err == nil +} + // parseLsListLine parses a directory line in a format based on the output of // the UNIX ls command. func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) { @@ -127,10 +132,24 @@ func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, er e := &Entry{ Name: scanner.Remaining(), } + sizeIndex := 4 + timeIndex := 5 + + // Assume group or user is missing + if !isNumber(fields[2]) && isNumber(fields[3]) { + sizeIndex = 3 + timeIndex = 4 + if len(e.Name) > 0 { + e.Name = fields[7] + " " + e.Name + } else { + e.Name = fields[7] + } + } + switch fields[0][0] { case '-': e.Type = EntryTypeFile - if err := e.setSize(fields[4]); err != nil { + if err := e.setSize(fields[sizeIndex]); err != nil { return nil, err } case 'd': @@ -147,7 +166,7 @@ func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, er return nil, errUnknownListEntryType } - if err := e.setTime(fields[5:8], now, loc); err != nil { + if err := e.setTime(fields[timeIndex:timeIndex+3], now, loc); err != nil { return nil, err } diff --git a/parse_test.go b/parse_test.go index 8bcd45a..99e629b 100644 --- a/parse_test.go +++ b/parse_test.go @@ -48,6 +48,9 @@ var listTests = []line{ {"drwxr-xr-x folder 0 Aug 15 05:49 !!!-Tipp des Haus!", "!!!-Tipp des Haus!", 0, EntryTypeFolder, newTime(thisYear, time.August, 15, 5, 49)}, {"drwxrwxrwx folder 0 Aug 11 20:32 P0RN", "P0RN", 0, EntryTypeFolder, newTime(thisYear, time.August, 11, 20, 32)}, {"-rw-r--r-- 0 18446744073709551615 18446744073709551615 Nov 16 2006 VIDEO_TS.VOB", "VIDEO_TS.VOB", 18446744073709551615, EntryTypeFile, newTime(2006, time.November, 16)}, + {"-rw-rw-rw- 1 generic 103344 Jan 03 15:12 test.pdf", "test.pdf", 103344, EntryTypeFile, newTime(thisYear, time.January, 3, 15, 12)}, + {"drw-rw-rw- 3 generic 4096 Jan 03 16:31 pub", "pub", 0, EntryTypeFolder, newTime(thisYear, time.January, 3, 16, 31)}, + {"-rw-rw-rw- 1 generic 29203 Jan 08 13:22 first_part second.part third.part.xml", "first_part second.part third.part.xml", 29203, EntryTypeFile, newTime(thisYear, time.January, 8, 13, 22)}, // Microsoft's FTP servers for Windows {"---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z", "ls-lR.Z", 1803128, EntryTypeFile, newTime(thisYear, time.July, 10, 10, 18)},