ssh2-streams icon indicating copy to clipboard operation
ssh2-streams copied to clipboard

mkdir -p not executing

Open pantos27 opened this issue 8 years ago • 10 comments

I tried the solution in this issue to create multiple directories but could no make it work. #4

Is there an alternative method or a more detailed example of this use case?

pantos27 avatar Oct 02 '17 08:10 pantos27

Can you provide more information? Is there an error? Is there text on the stream.stderr stream? Does mkdir return a non-zero exit code?

mscdex avatar Oct 02 '17 08:10 mscdex

There's no error code or an error event. Here's one of the variations I have tried

conn.on('ready', function () {
        console.log('uploadSsh2 :: ready');
             conn.exec('mkdir -p -f '+PATH.dirname(destPath),(err,channel)=>{
            if(err){
                conn.end();
                callback(err);
            }else{
                console.log('ok');
                channel.addListener('close',()=>{
                    console.log('close');                
                });
                channel.addListener('end',()=>{
                    console.log('end');                
                })
                channel.addListener('data',()=>{
                    console.log('data');                
                })                
                channel.addListener('readable',()=>{
                    console.log('readable');                
                })                
                channel.resume();                
                channel.stderr.resume();
                console.log('resumed');               
            }
        })
    }).on('error',(err)=>{
        conn.end();
        callback(err);
    }).connect(server);

pantos27 avatar Oct 02 '17 10:10 pantos27

You're ignoring any stderr data in that code (channel.stderr.resume()). Instead, try logging the output:

channel.stderr.pipe(process.stderr);

Also check the exit code passed to the 'exit' and 'close' event handlers.

mscdex avatar Oct 02 '17 10:10 mscdex

I'm sorry I can't seem to make this work Can you please add the required lines to this code to create the path one/two/three

const Client = require('ssh2').Client;
    var conn = new Client();    
 conn.on('ready', function () {

//mkdir....

}).on('error',(err)=>{
        conn.end();
        callback(err);
    }).connect(server);

pantos27 avatar Oct 24 '17 15:10 pantos27

Did you check the stderr output? What exit status code (and/or signal) are you receiving in the 'exit' event handler?

mscdex avatar Oct 24 '17 20:10 mscdex

No output in stderr and no exit code.

On Oct 24, 2017 11:51 PM, "Brian White" [email protected] wrote:

Did you check the stderr output? What exit status code (and/or signal) are you receiving in the 'exit' event handler?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mscdex/ssh2-streams/issues/84#issuecomment-339127041, or mute the thread https://github.com/notifications/unsubscribe-auth/ADCnaPfo0MLJsy9JZqbmE1Y50DdnARAMks5svk3KgaJpZM4PqTl- .

pantos27 avatar Oct 24 '17 20:10 pantos27

There has to be either an exit code or signal when the remote child process exits. Did you add something like this:

channel.on('exit', (code, signal) => {
  console.log('code', code, 'signal', signal);
});

?

mscdex avatar Oct 24 '17 23:10 mscdex

I have. Both are undefined This is on an sftp server if it make any difference

pantos27 avatar Oct 25 '17 07:10 pantos27

@pantos27 , did you get it working eventually? I have the same issue ... and no logs at all to help

nosteine avatar Jan 15 '18 14:01 nosteine

@nosteine nope. Ended up using a different module https://www.npmjs.com/package/ftps

pantos27 avatar Jan 15 '18 21:01 pantos27