UNPKG

ftp-srv-u

Version:
40 lines (32 loc) 1.08 kB
const Promise = require('bluebird'); const path = require('path'); const _ = require('lodash'); module.exports = { directive: 'RNTO', handler: function ({log, command} = {}) { if (!this.renameFrom) return this.reply(503); if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.rename) return this.reply(402, 'Not supported by file system'); const from = this.renameFrom; const to = command.arg; //过滤指定文件拓展名 if (_.includes(this.server.options.deny_extension, _.lowerCase(path.extname(to))) ) { return this.reply(550, 'file extension blacklisted'); } return Promise.try(() => this.fs.rename(from, to)) .then(() => { return this.reply(250); }) .tap(() => this.emit('RNTO', null, to)) .catch((err) => { log.error(err); this.emit('RNTO', err); return this.reply(550, err.message); }) .finally(() => { delete this.renameFrom; }); }, syntax: '{{cmd}} <name>', description: 'Rename to' };