Skip to content
30 changes: 15 additions & 15 deletions lib/ftpd.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,22 +543,22 @@ FtpConnection.prototype._command_FEAT = function(commandArg) {
);
};

FtpConnection.prototype._command_MDTM = function (commandArg) {
var self = this;

var file = withCwd(self.cwd, commandArg);

self.fs.stat(file, function (err, stats) {
/**
* Print the file modification time
* @param {string} file
* @return {FtpConnection} this
*/
FtpConnection.prototype._command_MDTM = function (file) {
file = withCwd(this.cwd, file);
file = pathModule.join(this.root, file);
this.fs.stat(file, function (err, stats) {
if (err) {
if (err.code == 'ENOENT')
self.respond("550 Not found");
else
self.respond("550 Error attempting to determine modification time");
return;
}

self.respond("213 " + dateformat(stats.mtime, "yyyymmddhhMMss") + "");
});
this.respond("550 File unavailable");
} else {
this.respond("213 " + dateformat(stats.mtime, "yyyymmddhhMMss"));
}
}.bind(this));
return this;
};

FtpConnection.prototype._command_LIST = function(commandArg) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ftpd",
"version": "0.2.6",
"version": "0.2.7",
"description": "Node FTP Server",
"main": "./lib/ftpd.js",
"scripts": {
Expand Down
33 changes: 33 additions & 0 deletions test/mdtm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var common = require('./common');

describe('MDTM command', function () {
'use strict';

var client;
var server;

beforeEach(function (done) {
server = common.server();
client = common.client(done);
});

it('should respond 213 for a valid file', function (done) {
client.raw('MDTM', '/data.txt', function (error, response) {
common.should.not.exist(error);
response.text.should.match(/^213 [0-9]{14}$/);
done();
});
});

it('should respond 550 for an invalid file', function (done) {
client.raw('MDTM', '/data2.txt', function (error, response) {
error.code.should.equal(550);
done();
});
});

afterEach(function () {
server.close();
});
});