@@ -30,6 +30,8 @@ const (
3030// Time format used by the MDTM and MFMT commands
3131const timeFormat = "20060102150405"
3232
33+ var ErrNotSupported = errors .New ("Not supported by remote FTP server" )
34+
3335// ServerConn represents the connection to a remote FTP server.
3436// A single connection only supports one in-flight data connection.
3537// It is not safe to be called concurrently.
@@ -654,6 +656,35 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
654656 return entries , err
655657}
656658
659+ // Stat issues an MLST command which returns info for a single entry
660+ func (c * ServerConn ) Stat (path string ) (entry * Entry , err error ) {
661+ if ! c .mlstSupported {
662+ return nil , ErrNotSupported
663+ }
664+
665+ cmd := "MLST"
666+ parser := parseRFC3659ListLine
667+
668+ space := " "
669+ if path == "" {
670+ space = ""
671+ }
672+
673+ _ , msg , errCmd := c .cmd (StatusRequestedFileActionOK , "%s%s%s" , cmd , space , path )
674+ if errCmd != nil {
675+ return nil , errCmd
676+ }
677+
678+ scanner := bufio .NewScanner (strings .NewReader (msg ))
679+ for scanner .Scan () {
680+ parseEntry , parseErr := parser (strings .TrimLeft (scanner .Text (), " " ), time .Now (), c .options .location )
681+ if parseErr == nil {
682+ return parseEntry , parseErr
683+ }
684+ }
685+ return nil , scanner .Err ()
686+ }
687+
657688// IsTimePreciseInList returns true if client and server support the MLSD
658689// command so List can return time with 1-second precision for all files.
659690func (c * ServerConn ) IsTimePreciseInList () bool {
0 commit comments