Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't parse LIST response line with parseDirListLine #350

Open
arian opened this issue Oct 4, 2023 · 3 comments
Open

Can't parse LIST response line with parseDirListLine #350

arian opened this issue Oct 4, 2023 · 3 comments
Labels
defect The code does not work as intended

Comments

@arian
Copy link

arian commented Oct 4, 2023

Describe the bug

I'm using the List function with a FTP server that returns a line like this:

08-03-2021  09:59AM       <DIR>          SomeDirectory

When debugging the parseDirListLine function, it doesn't recognize the dirTimeFormat.

To Reproduce

A program like this:

func main() {
	c, err := ftp.Dial("ftp.example.com:21", ftp.DialWithTimeout(5*time.Second))
	if err != nil {
		log.Fatal(err)
	}

	err = c.Login("user", "pass")
	if err != nil {
		log.Fatal(err)
	}

	entries, err := c.List("/")
	if err != nil {
		log.Fatal(err)
	}

	for _, entry := range entries {
		log.Println(entry.Name)
	}

	if err := c.Quit(); err != nil {
		log.Fatal(err)
	}
}

Expected behavior

It returns and prints the directory as entry.

FTP server

  • Name and version:
  • Public URL if applicable
> quote SYST
215 Windows_NT
> quote FEAT
211-Extended features supported:
LANG EN*
UTF8
AUTH TLS;TLS-C;SSL;TLS-P;
PBSZ
PROT C;P;
CCC
HOST
SIZE
MDTM
REST STREAM
211 END

Suggested solution

I think it could be fixed by adding 01-02-2006 03:04PM to the dirTimeFormats in parse.go.

@arian arian added the defect The code does not work as intended label Oct 4, 2023
@ZH-21000301
Copy link

ZH-21000301 commented Nov 15, 2023

I also encountered similar problems on Kylin OS.
Kylin OS return dirTimeFormat is "02 01月 2006 15:04" when using LIST function
So I added a new time parse in parse.go file

func (e *Entry) setTime(fields []string, now time.Time, loc *time.Location) (err error) {
      if strings.Contains(fields[2], ":") { // contains time
		thisYear, _, _ := now.Date()
		timeStr := fmt.Sprintf("%s %s %d %s", fields[1], fields[0], thisYear, fields[2])
		e.Time, err = time.ParseInLocation("_2 Jan 2006 15:04", timeStr, loc)
		// added code
		if err != nil{
			layout := "02 01月 2006 15:04"
			e.Time, err = time.ParseInLocation(layout, timeStr, loc)
		}
                // xxxxx
       }
}

@esperlu
Copy link
Contributor

esperlu commented Nov 20, 2023

Same problem here with a Windows_NT FTP server that returns files and directories with a "01-02-2006 03:04PM" format.

I modified the parse.go source with the adequate formats :

var dirTimeFormats = []string{
	"01-02-06  03:04PM",
	"01-02-2006  03:04PM",
	"2006-01-02  15:04",
	"2006-01-02  03:04PM",
	"2006-01-02  03:04PM",
}

Problem is that the list func returns now the file and dir names but without the time stamps.

@funkyshu
Copy link

This appears to have been fixed in #354 but no new release has been created. Should work with pseudo modules by doing go get github.com/jlaffaye/ftp@master to pull in the latest master commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect The code does not work as intended
Projects
None yet
Development

No branches or pull requests

4 participants