Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: (SSH) Channel open failure: open failed #219

Closed
xingyunshisui opened this issue Jan 28, 2015 · 4 comments
Closed

Error: (SSH) Channel open failure: open failed #219

xingyunshisui opened this issue Jan 28, 2015 · 4 comments

Comments

@xingyunshisui
Copy link

When I call Connection.sftp() method frequently(<1s), I got this error throwed. Before invoke conn.sftp(), my ssh connection is ready to use.
This is my throw err function:

function sendFile(filepath) {
  conn.sftp(function(err, sftp) {
    if (err) {
      logger.error('conn.sftp error: ' + err) // error throw from this
    } else {
      var remotePath = BASE_DIR + remoteDirName + '/' +
        path.basename(filepath, '.dbf') + +new Date + '.dbf'
      sftp.fastPut(filepath, remotePath, function(err) {
        if (err) {
          logger.error('sftp.fastPut error: ' + err)
        }
      })
    }
  })
}

ENV:
ssh2: 0.3.6
NodeJS: 0.10.28
OS: Windows 7

@mscdex
Copy link
Owner

mscdex commented Jan 28, 2015

It's possible that you're hitting the max number of open channels for a connection (conn.sftp() opens a new channel, just like conn.exec(), conn.shell(), etc). You really only need to call conn.sftp() once. You can re-use the sftp object passed to the callback as much as you want, but be sure to call sftp.end() to close the sftp channel once you are done with all of your sftp requests.

If you have sufficient access on the server, you might try bumping up the log verbosity in the /etc/ssh/sshd_config and then verifying that the max channel limit is in fact being reached or if it's something else.

@xingyunshisui
Copy link
Author

@mscdex
I have upgrade my code like you said, keep sftp as a global object and continuously invoke sftp.fastPut(). It's ok this time but occurs 2 new issues:

  1. sometimes sftp.fastPut() callback catch err: Error: Failure
  2. sftp server received more and more empty files as time goes on. I guess this is because a connection doesn't start to write fileA yet, another put request reuse the connection to write other fileB, so although fileA has created, but nothing write in it.

Sorry for my poor Chinese-English XD...

@mscdex
Copy link
Owner

mscdex commented Jan 28, 2015

  1. The problem could be anything from a permissions issue to the destination file path already existing. OpenSSH isn't very descriptive with errors they send across the wire.
  2. Writing to different files in parallel should not be a problem, provided nothing else is already writing to those files...

@nitishrai
Copy link

nitishrai commented Jul 8, 2016

@mscdex
Hi brian can u help me in this plz i can make it through socket so that i can get realtime shell

var conn = new Connection();
        conn.connect(login);
        conn.on('ready', function() {
            console.log('Client :: ready');
        socket.on('new message', function(msg) {
            conn.shell(true, function(err, stream) {
                if (err) throw err;
                stream.on('close', function() {
                    console.log('Stream :: close');
                    conn.end();
                }).on('data', function(data) {
                    console.log('' + data);
                }).stderr.on('data', function(data) {
                    console.log('STDERR: ' + data);
                });
                stream.write(msg);
            })
        });

Can u help me in this to do so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants