forked from QuorumDMS/ftp-srv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdtm.js
More file actions
26 lines (24 loc) · 970 Bytes
/
mdtm.js
File metadata and controls
26 lines (24 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// bluebird & moment removed, using native Date
module.exports = {
directive: 'MDTM',
handler: function ({log, command} = {}) {
if (!this.fs) return this.reply(550, 'File system not instantiated');
if (!this.fs.get) return this.reply(402, 'Not supported by file system');
return Promise.resolve().then(() => this.fs.get(command.arg))
.then((fileStat) => {
const d = new Date(fileStat.mtime);
const pad = (n, l=2) => String(n).padStart(l,'0');
const modificationTime = `${d.getUTCFullYear()}${pad(d.getUTCMonth()+1)}${pad(d.getUTCDate())}${pad(d.getUTCHours())}${pad(d.getUTCMinutes())}${pad(d.getUTCSeconds())}.${pad(d.getUTCMilliseconds(),3)}`;
return this.reply(213, modificationTime);
})
.catch((err) => {
log.error(err);
return this.reply(550, err.message);
});
},
syntax: '{{cmd}} <path>',
description: 'Return the last-modified time of a specified file',
flags: {
feat: 'MDTM'
}
};