From e597fbc78ff60ce495eecd9ffdffda801ed90b66 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 13 Feb 2024 14:32:21 +0000 Subject: [PATCH] fix(FTP Node): Fix issue with connections not closing properly (#8619) --- packages/nodes-base/nodes/Ftp/Ftp.node.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/nodes/Ftp/Ftp.node.ts b/packages/nodes-base/nodes/Ftp/Ftp.node.ts index 252ccabcb9620..19e8f2cff1b22 100644 --- a/packages/nodes-base/nodes/Ftp/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp/Ftp.node.ts @@ -439,8 +439,8 @@ export class Ftp implements INodeType { credential: ICredentialsDecrypted, ): Promise { const credentials = credential.data as ICredentialDataDecryptedObject; + const ftp = new ftpClient(); try { - const ftp = new ftpClient(); await ftp.connect({ host: credentials.host as string, port: credentials.port as number, @@ -448,11 +448,13 @@ export class Ftp implements INodeType { password: credentials.password as string, }); } catch (error) { + await ftp.end(); return { status: 'Error', message: error.message, }; } + await ftp.end(); return { status: 'OK', message: 'Connection successful!', @@ -463,8 +465,8 @@ export class Ftp implements INodeType { credential: ICredentialsDecrypted, ): Promise { const credentials = credential.data as ICredentialDataDecryptedObject; + const sftp = new sftpClient(); try { - const sftp = new sftpClient(); if (credentials.privateKey) { await sftp.connect({ host: credentials.host as string, @@ -483,11 +485,13 @@ export class Ftp implements INodeType { }); } } catch (error) { + await sftp.end(); return { status: 'Error', message: error.message, }; } + await sftp.end(); return { status: 'OK', message: 'Connection successful!', @@ -511,10 +515,9 @@ export class Ftp implements INodeType { } else { credentials = await this.getCredentials('ftp'); } + let ftp: ftpClient; + let sftp: sftpClient; try { - let ftp: ftpClient; - let sftp: sftpClient; - if (protocol === 'sftp') { sftp = new sftpClient(); if (credentials.privateKey) { @@ -809,6 +812,11 @@ export class Ftp implements INodeType { await ftp!.end(); } } catch (error) { + if (protocol === 'sftp') { + await sftp!.end(); + } else { + await ftp!.end(); + } if (this.continueOnFail()) { return [[{ json: { error: error.message } }]]; }