1

Hi I am trying to read a file from a remote sftp server using 'ssh2-sftp-client' module.

I need to create a function to read file from sftp and return the stream to the calling function .

In the below snippent I am getting a buffer as response to sftpGet( ) call . How get readable stream as response.

let Client = require('ssh2-sftp-client');
async function start() {
    let config = {
        host: 'XXXXX,
        username: 'XXX',
        password: 'XXX',
        port: 22,
        algorithms: {
            kex: [
                'diffie-hellm`enter code here`an-group1-sha1', //key exchange
            ],
            cipher: [
            ]
        }
    }

let path = 'remotePath/RemoteNew.txt'
        var resp = await sftpGet(config, path);


}
async function sftpGet(config, remotePath) {
    var sftp = new Client();
    var data = sftp.connect(config).then(() => {
        return sftp.get(remotePath);
    }).then(data => {
        sftp.end()
       return data;
    }).catch(err => {
        console.log(err, 'catch error');
        sftp.end()
        return err;
    });
  
    return data;
}

0 Answers0