在上一个问题中,我询问是否可以使用 node.js 从远程 SSH 会话运行 telnet 会话。我通常通过 SSH putty 会话连接到 linux 服务器,然后 telnet 到另一个 idirect / 调制解调器。我想使用 node.js 以编程方式执行此操作。根据收到的答复,我知道我必须运行一个期望脚本来执行所需的 telnet 命令。
是否可以使用ssh2shell
or运行脚本simple-ssh
?
在上一个问题中,我询问是否可以使用 node.js 从远程 SSH 会话运行 telnet 会话。我通常通过 SSH putty 会话连接到 linux 服务器,然后 telnet 到另一个 idirect / 调制解调器。我想使用 node.js 以编程方式执行此操作。根据收到的答复,我知道我必须运行一个期望脚本来执行所需的 telnet 命令。
是否可以使用ssh2shell
or运行脚本simple-ssh
?
我使用了 node-ssh。
您可以连接到实例,并且可以像这样使用它:
let sshConnection = ssh.connect({
host: <host>,
username: <username>,
privateKey: '/path/to/id-rsa'
})
sshConnection.then(() => {
ssh.putFile('./script.py', '/tmp/script.py').then(() => {
log('The File thing is done')
}, (error) => {
log('Somethings wrong', error)
})
})
sshConnection.then(() => {
ssh.execCommand(`echo hello-world`, { cwd: '/home' })
.then((result) => {
log(`result.stdout = ${result.stdout}`)
log(`result.stderr = ${result.stderr}`)
})
})