ssh2
ssh2 copied to clipboard
Question about forwaring
Hello,
I need to list the files present in a specific folder using ssh forwarding.
How do I translate this into ssh2 ?
$ ssh -A myAccount@myServer
// then, once connected
$ ssh myAccount@myInternalServerName
$ cd /to/specific/folder
$ ls
The code that I have put in place is not connecting to the myInternalServerName
conn
.on('ready', function() {
conn.exec('ssh -t myUsername@InternalServerName', function (err, stream) {
if (err) throw err;
conn.sftp(function(err, sftp) {
if (err) throw err;
sftp.readdir('/my/folder/', function(err, list) {
if (err) throw err;
console.dir(list);
conn.end();
});
});
});
})
.connect({
host: 'XX.XX.XX.XX',
port: 22,
username: 'myUsername',
passphrase: 'myPassPhrase',
privateKey: '/link/to/privateKey',
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
});
There's a connection hopping example in the readme. Also, you should remove privateKey if you are using an ssh-agent since it will take precedence over the ssh-agent.
Thanks for the quick answer.
Unfortunately I don't have nc (as the hopping example shows) available on the server.
The same is possible using a child_process and the command
ssh -A -t [email protected] ssh -A -t InternalServerName