From 4a6a3715b29a717f6ec6f8f30c817a4a05b58569 Mon Sep 17 00:00:00 2001 From: Ludovic Fauvet Date: Thu, 12 Jan 2017 22:24:01 +0100 Subject: [PATCH] RFC3659: add a new method to get the last modification time (MDTM) --- ftp.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ftp.go b/ftp.go index e4d7caf..4d26965 100644 --- a/ftp.go +++ b/ftp.go @@ -512,6 +512,28 @@ func (e *Entry) setTime(fields []string) (err error) { return } +func (c *ServerConn) LastModificationDate(path string) (t time.Time, err error) { + if _, mdtmSupported := c.features["MDTM"]; !mdtmSupported { + return t, errors.New("MDTM is not supported on this server") + } + + _, msg, err := c.cmd(StatusFile, "MDTM %s", path) + if err != nil { + return + } + + // Line formats: + // 213 20150413095032 + // 213 20150413095032.999 + if len(msg) < 14 { + return t, errors.New("Command unsupported on this server") + } + + gmtLoc, _ := time.LoadLocation("GMT") + t, err = time.ParseInLocation("20060102150405.999", msg, gmtLoc) + return +} + // NameList issues an NLST FTP command. func (c *ServerConn) NameList(path string) (entries []string, err error) { conn, err := c.cmdDataConnFrom(0, "NLST %s", path)