Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:01:27+00:00 2026-06-13T15:01:27+00:00

I was hoping I could get some advice on why my nodejs program is

  • 0

I was hoping I could get some advice on why my nodejs program is behaving in the way it is.

I am using two modules, node-sftp and node-inotify. I have setup node-inotify to watch a directory and call a function when something is written there, the function being an sftp upload.

Now the problem I have is that processing one file at a time is fine but when I drop 4 files in one go there, the function is called four times but only one sftp upload goes through.

Do I need to order my code in a particular way to ensure that the sftp upload occurs x times, is this something to do with closures perhaps?

This is a basic version of my code…

  • “event_handler” is called when something happens on a “watched” directory
  • “check_event” figures out if this type of event is one we want, in this case it’s a “write”
  • “ftp_to_server” prepare connection details
  • “do_ftp” basically uses the node-sftp module to perform the sftp upload

    event_handler = function(event){
        var supplier;
        check_event(event, supplier, type, ftp_to_server);
    };
    

=================

    function check_event(event, handler)
    {
        if (event.type === 'xxxxxx') {
            var file_to_process_name = 'abc';
            var file_to_process_dir = 'abc';
            var remote_dir = 'abc';
            handler(file_to_process_name, file_to_process_dir, remote_dir);
        }
    }

    function ftp_to_server(file_to_process_name, file_to_process_dir, remote_dir) {
        var connection_details = conf.ftp.connections
        do_ftp(connection_details, file_to_process_name, file_to_process_dir, remote_dir);    
    }

    function do_ftp(connection_details, file_to_process_name, file_to_process_dir, remote_dir) {

        var credentials = {
            // FTP settings here
        };
        var local_file = file_to_process_dir + file_to_process_name;
        var remote_file = remote_dir + file_to_process_name;

        connection = new sftp(credentials, function(err) {
            if (err){
                throw err;
            }
            connection.writeFile(remote_file, fs.readFileSync(local_file, "utf8"), null, function(err) {
                if (err) {
                    throw err;
                }

                console.info('FTP PUT DONE');

            });
        });
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:01:28+00:00Added an answer on June 13, 2026 at 3:01 pm

    Your “connection = new sftp(credentials, function(err) {”
    should be
    var connection = new sftp(credentials, function(err) {

    The way you currently have it coded, “connection” is a global and you are writing over it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was hoping I could get some input on the best way to handle
Hi I was hoping I could get some help on how to optimize my
I have been playing with generics and was hoping I could get some feedback
I was hoping I could get some help from you guys. The code below
I was hoping I could get some help figuring out why a bit of
I was hoping I could get some help with a Query I am trying
I was hoping I could get some help on the following problem. Basically, I
I was hoping I could get some help optimizing the following data retrieval. Here
I am developing a magnifying glass and I was hoping I could get some
I brought my laptop home from work hoping I could get some tasks done

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.