Skip to content

Commit 97aea73

Browse files
committed
Add GetEntryInfo based on MLST command
1 parent 901caa1 commit 97aea73

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ftp.go

+28
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,34 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
654654
return entries, err
655655
}
656656

657+
func (c *ServerConn) GetEntryInfo(path string) (entry *Entry, err error) {
658+
if !c.mlstSupported {
659+
return nil, errors.New("GetEntryInfo is not supported")
660+
}
661+
662+
cmd := "MLST"
663+
parser := parseRFC3659ListLine
664+
665+
space := " "
666+
if path == "" {
667+
space = ""
668+
}
669+
670+
_, msg, errCmd := c.cmd(StatusRequestedFileActionOK, "%s%s%s", cmd, space, path)
671+
if errCmd != nil {
672+
return nil, errCmd
673+
}
674+
675+
scanner := bufio.NewScanner(strings.NewReader(msg))
676+
for scanner.Scan() {
677+
parseEntry, parseErr := parser(strings.TrimLeft(scanner.Text(), " "), time.Now(), c.options.location)
678+
if parseErr == nil {
679+
return parseEntry, parseErr
680+
}
681+
}
682+
return nil, scanner.Err()
683+
}
684+
657685
// IsTimePreciseInList returns true if client and server support the MLSD
658686
// command so List can return time with 1-second precision for all files.
659687
func (c *ServerConn) IsTimePreciseInList() bool {

0 commit comments

Comments
 (0)