Add delete folder operation to FTP Node (#1704)

*  Add delete folder operation to FTP Node

*  Minor improvement

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza 2021-04-30 15:19:59 -04:00 committed by GitHub
parent b6d45e30ef
commit 901551ae99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
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;
if (options.folder === true) {
responseData = await ftp!.rmdir(path, !!options.recursive);
} else {
responseData = await ftp!.delete(path);
}
returnItems.push({ json: { success: true } });
}