У меня проблема с загрузкой данных ftp (в данном случае pdf) с ftp-сервера через api моего узла, который работает в движке приложения googles. Это мой код:
const Client = require('node-ftp')
const streams = require('memory-streams')
exports.downloadRekla = async function (req, res, next) {
let writer = new streams.WritableStream();
let c = new Client();
let config = {
host: "xxx",
user: "xxx",
password: "xxx",
secure: false
}
c.on('ready', function () {
c.get(`${req.params.banr}_Reklamation.pdf`, function (err, stream) {
if (err) {
// FTP Code 550 = Requested action not taken. File unavailable (e.g., file not found, no access).
if (err.code == 550) {
// Don't send if no file with this name exists
console.log(`${req.params.banr}_Reklamation.pdf nicht vorhanden.`);
res.status(200).send();
c.end();
} else {
throw err;
}
} else {
stream.once('close', function () {
writer.end();
console.log('send res');
res.send(writer.toBuffer());
c.end();
console.log('bye');
});
console.log('write data in writable stream');
stream.pipe(writer);
console.log('done writing stuff in stream')
}
});
});
c.on('error', function () {
console.log('close connection');
c.end();
setTimeout(() => {
console.log('attempting to reconnect');
c.connect(config);
console.log('reconnected');
}, 2000);
});
console.log('attempting to connect to ftp server');
c.connect(config);
console.log('connected');}
проблема в том, что я не получаю никакого ответа, просто 502 плохой шлюз ... какие-либо идеи о том, что я делаю здесь неправильно?
Кроме того, планируется записать pdf-данные в поток для записи, преобразовать их в буфер и создать pdf-файл из этих данных в моем интерфейсе.