ssh2 icon indicating copy to clipboard operation
ssh2 copied to clipboard

Question about forwaring

Open btx0 opened this issue 11 years ago • 2 comments

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
  });

btx0 avatar May 19 '15 09:05 btx0

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.

mscdex avatar May 19 '15 09:05 mscdex

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

btx0 avatar May 19 '15 13:05 btx0