From 901551ae9905d20444c29726249543908761453e Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 30 Apr 2021 15:19:59 -0400 Subject: [PATCH] :zap: Add delete folder operation to FTP Node (#1704) * :zap: Add delete folder operation to FTP Node * :zap: Minor improvement Co-authored-by: Jan Oberhauser --- packages/nodes-base/nodes/Ftp.node.ts | 56 +++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Ftp.node.ts b/packages/nodes-base/nodes/Ftp.node.ts index 12835376e0..ef254b055d 100644 --- a/packages/nodes-base/nodes/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp.node.ts @@ -102,7 +102,7 @@ export class Ftp implements INodeType { { name: 'Delete', value: 'delete', - description: 'Delete a file.', + description: 'Delete a file/folder.', }, { name: 'Download', @@ -148,6 +148,46 @@ export class Ftp implements INodeType { required: true, }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + displayOptions: { + show: { + operation: [ + 'delete', + ], + }, + }, + default: {}, + options: [ + { + displayName: 'Folder', + name: 'folder', + type: 'boolean', + default: false, + description: 'When set to true, folders can be deleted.', + required: true, + }, + { + displayName: 'Recursive', + displayOptions: { + show: { + folder: [ + true, + ], + }, + }, + name: 'recursive', + type: 'boolean', + default: false, + description: 'If true, remove all files and directories in target directory.', + required: true, + }, + ], + }, + // ---------------------------------- // download // ---------------------------------- @@ -401,8 +441,13 @@ export class Ftp implements INodeType { if (operation === 'delete') { const path = this.getNodeParameter('path', i) as string; + const options = this.getNodeParameter('options', i) as IDataObject; - responseData = await sftp!.delete(path); + if (options.folder === true) { + responseData = await sftp!.rmdir(path, !!options.recursive); + } else { + responseData = await sftp!.delete(path); + } returnItems.push({ json: { success: true } }); } @@ -488,8 +533,13 @@ export class Ftp implements INodeType { if (operation === 'delete') { const path = this.getNodeParameter('path', i) as string; + const options = this.getNodeParameter('options', i) as IDataObject; - responseData = await ftp!.delete(path); + if (options.folder === true) { + responseData = await ftp!.rmdir(path, !!options.recursive); + } else { + responseData = await ftp!.delete(path); + } returnItems.push({ json: { success: true } }); }