-
-
Save mscdex/7c9f8358b8331ea567b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var Connection = require('ssh2'); | |
var c = new Connection(); | |
c.on('ready', function() { | |
c.exec('bash -s', function(err, stream) { | |
if (err) throw err; | |
// allow us to close stdin but still allow output from server | |
stream.allowHalfOpen = true; | |
fs.createReadStream('localscript.sh') | |
.pipe(stream) | |
.on('data', function(data, extended) { | |
console.log((extended === 'stderr' ? 'STDERR: ' : 'STDOUT: ') | |
+ data); | |
}).on('exit', function(code, signal) { | |
c.end(); | |
}); | |
}); | |
}).connect({ | |
host: 'server', | |
port: 22, | |
username: 'user', | |
agent: process.env.SSH_AUTH_SOCK | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment