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

Cannot create writeStream #75

Closed
ScottRandallWay opened this issue May 10, 2022 · 3 comments
Closed

Cannot create writeStream #75

ScottRandallWay opened this issue May 10, 2022 · 3 comments

Comments

@ScottRandallWay
Copy link

ScottRandallWay commented May 10, 2022

We had existing code that used ssh2 to write a string to a file and it worked for several years. We upgraded to ssh2-promise now it seems we are not getting a valid writestream. We just keep getting writestream.write is not a function. Are we doing something wrong?

                let conn = new SSH2Promise(this.connSettings);
                var sftp = conn.sftp();
                var writeStream = sftp.createWriteStream(targetFile).then(() => {
                    writeStream.write(dataContent, {mode: 0o777});
                    writeStream.end();
                    writeStream.on('close', () => {
                        conn.close();
                        resolve(targetFile);
                    })
                }).catch ((err) => {
                    logger.error({
                        object: 'Scp',
                        op: 'writeData',
                        targetFile: targetFile,
                        err: err
                    }, 'op: Scp.writeData, targetFile: ' + targetFile + ', error: ' + err);
                    reject('WriteStream Failed');
                });
@ScottRandallWay
Copy link
Author

Additionally we figured out this code seems to work fine on windows (our dev workstations), but is failing on Centos 7 which is our dev and test servers.

@CRAKZOR
Copy link

CRAKZOR commented May 21, 2022

Additionally we figured out this code seems to work fine on windows (our dev workstations), but is failing on Centos 7 which is our dev and test servers.

use node version <= 17.8.0

@sanketbajoria
Copy link
Owner

sanketbajoria commented Jun 6, 2022

@ScottRandallWay
Actually you are doing little bit wrong. We can access WriteStream in below manner, if using promise (thenable)

sftp.createWriteStream(targetFile).then((writeStream) => {
                    writeStream.write(dataContent, {mode: 0o777});
});

I will update readme around it.

For example:
https://github.com/sanketbajoria/ssh2-promise/blob/master/spec/sftp-spec.js#L73

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