mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(FTP Node): Continue of fail looping support with paired item (#8659)
This commit is contained in:
parent
bee17dd6cc
commit
3279762221
|
@ -18,7 +18,7 @@ import type {
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { formatPrivateKey } from '@utils/utilities';
|
import { formatPrivateKey, generatePairedItemData } from '@utils/utilities';
|
||||||
|
|
||||||
interface ReturnFtpItem {
|
interface ReturnFtpItem {
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -515,6 +515,8 @@ export class Ftp implements INodeType {
|
||||||
}
|
}
|
||||||
let ftp: ftpClient;
|
let ftp: ftpClient;
|
||||||
let sftp: sftpClient;
|
let sftp: sftpClient;
|
||||||
|
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
if (protocol === 'sftp') {
|
if (protocol === 'sftp') {
|
||||||
sftp = new sftpClient();
|
sftp = new sftpClient();
|
||||||
|
@ -544,8 +546,17 @@ export class Ftp implements INodeType {
|
||||||
password: credentials.password as string,
|
password: credentials.password as string,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (this.continueOnFail()) {
|
||||||
|
const pairedItem = generatePairedItemData(items.length);
|
||||||
|
|
||||||
|
return [[{ json: { error: error.message }, pairedItem }]];
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
try {
|
||||||
const newItem: INodeExecutionData = {
|
const newItem: INodeExecutionData = {
|
||||||
json: items[i].json,
|
json: items[i].json,
|
||||||
binary: {},
|
binary: {},
|
||||||
|
@ -658,7 +669,10 @@ export class Ftp implements INodeType {
|
||||||
await sftp!.put(uploadData, remotePath);
|
await sftp!.put(uploadData, remotePath);
|
||||||
} else {
|
} else {
|
||||||
// Is text file
|
// Is text file
|
||||||
const buffer = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');
|
const buffer = Buffer.from(
|
||||||
|
this.getNodeParameter('fileContent', i) as string,
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
await sftp!.put(buffer, remotePath);
|
await sftp!.put(buffer, remotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +791,10 @@ export class Ftp implements INodeType {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Is text file
|
// Is text file
|
||||||
const buffer = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');
|
const buffer = Buffer.from(
|
||||||
|
this.getNodeParameter('fileContent', i) as string,
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
await ftp!.put(buffer, remotePath);
|
await ftp!.put(buffer, remotePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -797,6 +814,14 @@ export class Ftp implements INodeType {
|
||||||
returnItems = returnItems.concat(executionData);
|
returnItems = returnItems.concat(executionData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (this.continueOnFail()) {
|
||||||
|
returnItems.push({ json: { error: error.message }, pairedItem: { item: i } });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocol === 'sftp') {
|
if (protocol === 'sftp') {
|
||||||
|
@ -810,10 +835,6 @@ export class Ftp implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
await ftp!.end();
|
await ftp!.end();
|
||||||
}
|
}
|
||||||
if (this.continueOnFail()) {
|
|
||||||
return [[{ json: { error: error.message } }]];
|
|
||||||
}
|
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue