-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp-client.js
34 lines (27 loc) · 898 Bytes
/
ftp-client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Ftp = require('promise-ftp');
const ftpSettings = require('./../config/ftp-config');
exports.upload = async function (transfer) {
const ftp = new Ftp();
console.log(`FTP: connecting to rchilli`);
try {
const serverMessage = await ftp.connect(ftpSettings);
console.log(`FTP: connected to rchilli: ${serverMessage}`);
console.log(`FTP: file to be uploaded`);
//const input = Buffer.from(transfer.file, 'base64');
const input = transfer.filepath;
console.log(input);
const destPath = `${transfer.filename}`;
console.log(destPath);
await ftp.mkdir(`/${transfer.client}`, true);
await ftp.cwd(transfer.client);
await ftp.put(input, destPath);
console.log(`FTP: file uploaded`);
ftp.end();
console.log(`FTP: connection closed`);
return `success`;
} catch(err) {
ftp.end();
console.error(err);
throw err;
}
};