Run a git clone that requires a username and password?
Code
const SSH = require('node-ssh')
const ssh = new SSH()
async function test () {
await ssh.connect({
host: 'myIP',
username: 'root',
port: 22,
password: 'MyPassword',
tryKeyboard: true,
onKeyboardInteractive: (name, instructions, instructionsLang, prompts, finish) => {
console.log(name)
console.log(instructions)
console.log(instructionsLang)
console.log(prompts)
console.log(finish)
}
})
let res = await ssh.execCommand('git clone https://gitee.com/dtboy/platform.git')
console.log(res);
// ssh.requestShell
console.log('#')
// ssh.dispose()
}
test()
- This function,
onKeyboardInteractive, is never called - res
{ code: 128,
signal: undefined,
stdout: 'Cloning into \'platform\'...',
stderr:
'fatal: could not read Username for \'https://gitee.com\': No such device or address' }
What should I do, any help would be appreciated!
Many commands are required to interact with the keyboard, how to achieve this operation, for some examples, would be grateful
like the lib node-suppose
While most of your setup is correct, the error from what you've posted seems to be a domain resolution one. Try running a ping for gitee.com from ssh instead.
@steelbrain, Thank you for your reply
But you don't seem to understand my question
And I ended up doing it this way(Not very pretty) use ssh2 package
conn.shell(function (err, stream) {
if (err) throw err;
stream.on('close', function () {
console.log('Stream::close');
conn.end();
}).on('data', function (data) {
console.log('[OUTPUT]: ' + data);
if (data.indexOf('Username') != -1) {
console.log('The user name is matched');
stream.write('myusername\n')
}
if (data.indexOf('The password was matched') != -1) {
console.log('');
stream.write('mypass\n')
}
});
stream.write('git clone https://gitee.com/dtboy/platform.git\n');
setTimeout(() => {
stream.close()
}, 3000);
});
Can this library do something similar
We do have requestShell that returns the same stream, so you can use the same API while using a nicer connection API
Ugh, should've included this in my above message, but if you want a nicer API to write/read from streams, see https://github.com/steelbrain/expected-write
It's been a while since it was updated, but it should work still
@steelbrain ,Thank you very much
Can node-ssh implement similar functions? This is actually a common requirement