Hi there,

I am trying to implent a nodejs script that connects to one of our servers 
using sftp.

So far I can connect using child process and spawning a command such as...

sftp -o Port=22-o PasswordAuthentication=no-o 
UserKnownHostsFile=/home/carlton/.ssh/known_hosts-o 
IdentityFile=private_key-o StrictHostKeyChecking=no-o 
BatchMode=nodeploy@46.x.x.x:/home/carlton/to_process

Now this is the part that has me confused...

I then need to execute commands on the ftp server (e.g. list files, rename 
files) so I listen to the 'data' event....

sftp.stdout.on('data', function (data) {
    console.log('stdout: ' + data);

    sftp.stdin.write("ls -l\r\n");

    sftp.stdout.on('data', function(data){
        console.log('File list:', data.toString());
        
         // Parse file names here
         
        sftp.stdin.write("rename /home/carlton/FTP_test/to_process/old.php 
/home/ carlton /FTP_test/processed/new.php\n");
    });
});

Is this the correct way to structure things (i.e. creatiung event listener 
again for the 'data' event within the callback of the previous 'data' event 
listener)?
I found it hard to find any examples similar to what I need to do which 
made me think I haven't built this as it should have been.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to