You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently updated ssh2 from version 0.8.9 to 1.16 in my app, and I'm working on getting everything up and running again. One thing I noticed is that if there's an error inside sftp, it ends up crashing the whole client and closing the connection.
Is this something that's meant to happen? Do you think there's a way I can prevent this from happening?
This is my example, I try to create a writestream on a file in the homefolder of the user test but the file is owned by root, so writing should fail.
import{Client}from'ssh2';constclient=newClient();client.on('ready',()=>{client.sftp((err,sftp)=>{if(err)throw(err);varwriteStream=sftp.createWriteStream("/home/test/asd");writeStream.write("this is a test",(e)=>{if(e)throw(e);console.log("DATA WRITTEN");});writeStream.end();console.log("stream end");});}).on('end',()=>{console.log("END event");}).on('error',(err)=>{console.log("ERROR event",err);}).on('close',()=>{console.log("CLOSE event");}).connect({host: "....",port: 22,username: "....",password: "...."});
outputs:
stream end
ERROR event Error: Permission denied
at 101 (project\node_modules\ssh2\lib\protocol\SFTP.js:2854:19)
at SFTP.push (project\node_modules\ssh2\lib\protocol\SFTP.js:278:11)
at CHANNEL_DATA (project\node_modules\ssh2\lib\client.js:585:23)
at 94 (project\node_modules\ssh2\lib\protocol\handlers.misc.js:930:16)
at Protocol.onPayload (project\node_modules\ssh2\lib\protocol\Protocol.js:2059:10)
at AESGCMDecipherNative.decrypt (project\node_modules\ssh2\lib\protocol\crypto.js:987:26)
at Protocol.parsePacket [as _parse] (project\node_modules\ssh2\lib\protocol\Protocol.js:2028:25)
at Protocol.parse (project\node_modules\ssh2\lib\protocol\Protocol.js:313:16)
at Socket.<anonymous> (project\node_modules\ssh2\lib\client.js:773:21)
at Socket.emit (node:events:518:28) {
code: 3
}
END event
CLOSE event
My usecase / app is an ssh terminal with sftp functionality and if an sftp error occurs this now means I have to create a whole new client, clear the terminal, reauthenticate and so on.
In the old version the sftp subsystem would fail seperately from the "main" ssh connection and leave the client alone. My expectation would be that the write callback gets called with an error instead or something like that?
Thank you
The text was updated successfully, but these errors were encountered:
Coding-Kiwi
changed the title
SFTP Permission denied error crashed the whole connection
SFTP Permission denied error crashes the whole connection
Dec 31, 2024
I recently updated ssh2 from version 0.8.9 to 1.16 in my app, and I'm working on getting everything up and running again. One thing I noticed is that if there's an error inside sftp, it ends up crashing the whole client and closing the connection.
Is this something that's meant to happen? Do you think there's a way I can prevent this from happening?
This is my example, I try to create a writestream on a file in the homefolder of the user test but the file is owned by root, so writing should fail.
outputs:
My usecase / app is an ssh terminal with sftp functionality and if an sftp error occurs this now means I have to create a whole new client, clear the terminal, reauthenticate and so on.
In the old version the sftp subsystem would fail seperately from the "main" ssh connection and leave the client alone. My expectation would be that the write callback gets called with an error instead or something like that?
Thank you
The text was updated successfully, but these errors were encountered: