spmjs / node-scp2

[MAINTAINER WANTED] A pure javascript scp program based on ssh2.
384 stars 96 forks source link

event listeners for low level api are confusing to use #85

Closed orgicus closed 3 years ago

orgicus commented 7 years ago

Hi,

I've tried using the low level api for a download and attached all the listeners :

var client = new Client();
client.defaults({
        host:'IP_HERE',
        username:'USER_HERE',
        password:'PASS_HERE'
});

                client.on('transfer',function (buffer, uploaded, total) { console.log(buffer,uploaded,total,new Date()); });
                client.on('connect',function(){ console.log("on connect",new Date()) });
                client.on('ready',function(){ console.log("on ready",new Date()) });
                client.on('error',function(err){ console.error("on error",err,new Date()) });
                client.on('end',function(){ console.log("on end",new Date()) });
                client.on('close',function(){ console.log("on close",new Date()) });
                client.on('mkdir',function(dir){ console.log("on mkdir",dir,new Date()) });
                client.on('write',function(src){ console.log("on write",src,new Date()) });
                client.on('read',function(src){ console.log("on read",src,new Date()); downloadCompleteHandler(); });

client.download(filename,'./files/'+filename,function(err){ 
                        if(err) console.error(err); 
                });

I only see console messages for 'connect', 'ready' at the start, un-intuitively 'read' at the same time as the download callback, then, after I call close() on the client, 'end' and 'close' trigger.

'transfer' does not trigger at all.

Unless I'm not using the library properly, the events should be better explained in the repo's readme.

laispace commented 7 years ago

+1

seakeys commented 2 years ago

var client = new Client({ host: config.host, username: config.username, privateKey: config.privateKey, });

client.on('transfer', function (buffer, uploaded, total) { console.log(buffer, uploaded, total, new Date()); });

scp(config.localPath, { host: config.host, username: config.username, privateKey: config.privateKey, path: config.path }, client, err => { spinner.stop(); if (!err) { console.log(chalk.green("部署完毕")) } else { console.log("err", err) } })