@@ -30,6 +30,8 @@ const (
30
30
// Time format used by the MDTM and MFMT commands
31
31
const timeFormat = "20060102150405"
32
32
33
+ var ErrNotSupported = errors .New ("Not supported by remote FTP server" )
34
+
33
35
// ServerConn represents the connection to a remote FTP server.
34
36
// A single connection only supports one in-flight data connection.
35
37
// It is not safe to be called concurrently.
@@ -654,6 +656,35 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
654
656
return entries , err
655
657
}
656
658
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
+
657
688
// IsTimePreciseInList returns true if client and server support the MLSD
658
689
// command so List can return time with 1-second precision for all files.
659
690
func (c * ServerConn ) IsTimePreciseInList () bool {
0 commit comments