diff --git a/ftp.go b/ftp.go index 34377b2..b334c65 100644 --- a/ftp.go +++ b/ftp.go @@ -403,10 +403,12 @@ func parseDirListLine(line string) (*Entry, error) { // Try various time formats that DIR might use, and stop when one works. for _, format := range dirTimeFormats { - e.Time, err = time.Parse(format, line[:len(format)]) - if err == nil { - line = line[len(format):] - break + if len(line) > len(format) { + e.Time, err = time.Parse(format, line[:len(format)]) + if err == nil { + line = line[len(format):] + break + } } } if err != nil { diff --git a/parse_test.go b/parse_test.go index 1236605..0d373f7 100644 --- a/parse_test.go +++ b/parse_test.go @@ -58,6 +58,7 @@ var listTestsFail = []unsupportedLine{ {"drwxr-xr-x 3 110 1002 3 Dec 02 209 pub", "Invalid year format in time string"}, {"modify=20150806235817;invalid;UNIX.owner=0; movies", "Unsupported LIST line"}, {"Zrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin", "Unknown entry type"}, + {"total 1", "Unsupported LIST line"}, } func TestParseValidListLine(t *testing.T) {