From 00929148fa511245dee91fdac768a26403a7f392 Mon Sep 17 00:00:00 2001 From: Pedro Benevides Date: Mon, 22 Jun 2020 14:16:19 +0100 Subject: [PATCH 1/2] Emitting RNTO command events. --- lib/FtpConnection.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/FtpConnection.js b/lib/FtpConnection.js index 828e1a8..7fd8b44 100644 --- a/lib/FtpConnection.js +++ b/lib/FtpConnection.js @@ -1074,12 +1074,20 @@ FtpConnection.prototype._command_RNTO = function(commandArg) { var self = this; var fileto = withCwd(self.cwd, commandArg); self.fs.rename(pathModule.join(self.root, self.filefrom), pathModule.join(self.root, fileto), function(err) { + var status = 'success'; if (err) { + status = 'error'; self._logIf(LOG.ERROR, 'Error renaming file from ' + self.filefrom + ' to ' + fileto); self.respond('550 Rename failed' + (err.code === 'ENOENT' ? '; file does not exist' : '')); } else { self.respond('250 File renamed successfully'); } + // Adding event emitter for completed file renaming. + self.emit('file:rnto', status, { + fileFrom: self.filefrom, + fileTo: fileto, + error: err + }); }); }; From 1fd43162c4fabfbf4bd550615df4db1fecc537ae Mon Sep 17 00:00:00 2001 From: Pedro Benevides Date: Tue, 23 Jun 2020 12:28:23 +0100 Subject: [PATCH 2/2] Added extra data attributes in RNTO event to make it similar to file:stor event data. --- lib/FtpConnection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/FtpConnection.js b/lib/FtpConnection.js index 7fd8b44..e52712f 100644 --- a/lib/FtpConnection.js +++ b/lib/FtpConnection.js @@ -1086,7 +1086,8 @@ FtpConnection.prototype._command_RNTO = function(commandArg) { self.emit('file:rnto', status, { fileFrom: self.filefrom, fileTo: fileto, - error: err + errorState: Boolean(err), + error: (err || false) }); }); };