Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
How to download a file through FTP with a firebase function?

QUESTION:

Unfortunately, my function finishes execution within seconds instead of executing in full. This is apparently due to the fact that listeners are declared to stream the data: they are not promises I can await to my knowledge.

How may I have my firebase function execute in full ?


CODE:

exports.fifteenMinutesData = functions
.runWith(runtimeOpts)
.pubsub
.schedule('*/15 * * * *')
.timeZone('Etc/UTC')
.onRun((context) => {
    return (async() => {
        try {

            const Client = require('ftp');
            const c = new Client();
            
            c.connect({
                host: "...",
                user: "..."
            });
            
            c.on('ready', async function () {
                c.get('text.txt', async function (err, stream) {
                    if (err)
                        throw err;
                    var content = '';
                    stream.on('data', function (chunk) {
                        content += chunk.toString();
                    });
                    stream.on('end', function () {
                        (async () => {

                            try {
                                let data = content;

                                //etc....
                            }
                            catch(err) {
                                console.log("ERR: "+err);
                            }
                        })()
                    })
                })
            })
        }
        catch(err) {
            console.log("ERR: "+err)
        }
    })()
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You will need to promisify the result so the module is aware the value is asynchronous. Currently, your callback is not informing the module of anything so the execution exits immediately, you will want a format like

exports.fifteenMinutesData = functions
.runWith(runtimeOpts)
.pubsub
.schedule('*/15 * * * *')
.timeZone('Etc/UTC')
.onRun((context) => new Promise((resolve, reject) => 
{

});

Where you call resolve(data); for the success path and reject(err); for all error execution paths.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda