From f71112a73ba1cc2c34343d93ea20b29ba60d8b7a Mon Sep 17 00:00:00 2001 From: JbIPS Date: Mon, 11 Jun 2018 00:25:50 +0200 Subject: [PATCH] Handles file not found on FTP Some FTP servers return an empty array on stat. --- lib/unifile-ftp.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/unifile-ftp.js b/lib/unifile-ftp.js index ffdd7db..4b485dd 100644 --- a/lib/unifile-ftp.js +++ b/lib/unifile-ftp.js @@ -78,6 +78,7 @@ function callAPI(session, action, client, ...params) { if(err.code === 530) { throw new UnifileError(UnifileError.EACCES, 'Invalid credentials'); } + console.log(session, action, client, params); throw new UnifileError(UnifileError.EIO, err.message); }) .then((result) => { @@ -198,6 +199,8 @@ class FtpConnector { stat(session, path, ftpSession) { return callAPI(session, 'ls', ftpSession, path) .then((entries) => { + // Not found + if(entries.length === 0) throw new UnifileError(UnifileError.ENOENT, 'Not found'); // It's a file if(entries.length === 1) return toFileInfos(entries[0]); // It's a folder