mikeal / sequest

Simplified API for SSH and SFTP similar to request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When using an exec command the sftp subsystem is not set

chriskinsman opened this issue · comments

Ran into this when using against a locked down server.

Sending / Receiving files worked but random SFTP commands send via the command option would fail with an error message that the server only support sftp.

From the sftp CLI which set the subsystem everything worked great. Looks like SSH2 has the ability to set the subsystem.

Not familiar enough with SFTP to know if this is really an issue or not...

I tested it with the raw ssh2 code like this:

var conn = new Client();
conn.on('ready', function () {
    console.log('Client :: ready');
    conn.sftp(function (err, sftp) {
        if (err) throw err;
        sftp.readdir('/', function (err, list) {
            if (err) throw err;
            console.dir(list);
            conn.end();
        });
    });
}).connect({
    host: 'localhost',
    port: 22,
    username: 'root',
    privateKey: _sftpPrivateKey
});

This works where code like this:

    sequest('root@localhost', { command: 'ls', privateKey: _sftpPrivateKey }, function (err, stdout) {
        if (err) {
            logger.error(';s err: ', err);
        }
        console.log(stdout)
        return callback(null);
    });

Does not work. I suspect the issue is that under the covers ssh2 exposes ssh_streams.SFTPStream and uses it to encode commands to the sftp subsystem.

In this case it looks like the server I am talking to will not allow a generic exec for ls whereas it will accept SFTP readdir commands.

This might be out of scope for this library and I am fine with the maintainer making that decision.

One option might be to expose the sftp wrapper that SSH2 offers someone on the returned sequest object...