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

ssh.dispose method throwing error after migrating to node 18 #471

Open
parth19 opened this issue Oct 12, 2023 · 1 comment
Open

ssh.dispose method throwing error after migrating to node 18 #471

parth19 opened this issue Oct 12, 2023 · 1 comment

Comments

@parth19
Copy link

parth19 commented Oct 12, 2023

Here's abstract code to read a file on SFTP server using node-ssh.

It was working fine till I was using node 16. But the ssh.dispose statement started throwing error after I migrated to node 18.
It is still able to connect with server and read file, but throws error while desposing connection.

It seems upgrade is required on library to make it compatible with node 18. Would you be able to help check.
Thanks in advance for any info / support.

Error :

Error: No response from server at cleanupRequests (node_modules/ssh2/lib/protocol/SFTP.js:2730:15) at SFTP.push (node_modules/ssh2/lib/protocol/SFTP.js:191:7) at onCHANNEL_CLOSE (node_modules/ssh2/lib/utils.js:50:13) at ChannelManager.cleanup (/usr/src/app/node_modules/ssh2/lib/utils.js:200:7)

Code :

import { NodeSSH } from 'node-ssh';
async function readFile(path: string): Promise<string> {
     let ssh: NodeSSH | null = null;
    try {
     const ssh = new NodeSSH()
      await ssh.connect({
          host, username, password
       })
      const sftp = await ssh.requestSFTP();
      const fstream = sftp.createReadStream(path);

       return await convertStreamToString(fstream);   // local function to convert stream into a string format using chunks &  Buffer
     } catch() {
       // throw error
     } finally {
      await ssh?.dispose();
     }
}
@qiaer
Copy link

qiaer commented Dec 27, 2023

+1

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

2 participants