[英]Is it possible to run a script with ssh2shell or simple-ssh using node.js?
在上一個問題中,我詢問是否可以使用 node.js 從遠程 SSH 會話運行 telnet 會話。 我通常通過 SSH putty 會話連接到 linux 服務器,然后 telnet 到另一個 idirect/調制解調器。 我想使用 node.js 以編程方式執行此操作。 從收到的答案中,我明白我必須運行一個期望腳本來執行所需的 telnet 命令。
是否可以使用ssh2shell
或simple-ssh
運行腳本?
我使用了節點 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}`)
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.