Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!