theophilusx/ssh2-sftp-client

can someone help me with this? sftp.createReadStream

Manoharvuradi opened this issue · 7 comments

     await sftp.connect(sfgCredentials)
        .then(async () => {
            console.log("Connected to the FTP server...");
            if (recentFile) {
                const remoteFilePath = `/Inbox/${recentFile.name}`;
                const options = {
                    flags: 'r',
                    encoding: 'base64',  // Set encoding to 'base64'
                    autoClose: true,
                    start: 0,
                    end: 100
                };
                const readStream = sftp.createReadStream(remoteFilePath, options);
                let base64Data = '';
                 readStream.on('ready', () => {
                    console.log('Stream ready.');
                });

                readStream.on('data', (chunk) => {
                    console.log('Received base64 chunk:', chunk);
                    base64Data += chunk;
                });

            } else {
                console.error("No files named Employee_290MAC.001 found in /inbox");
            }
        }).then(() => {
            sftp.end();
        });

//In console
Connected to the FTP server...
node:events:495
throw er; // Unhandled 'error' event
^

Error: No response from server
at cleanupRequests (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\protocol\SFTP.js:2730:15)
at SFTP.push (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\protocol\SFTP.js:191:7)
at onCHANNEL_CLOSE (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\utils.js:50:13)
at ChannelManager.cleanup (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\utils.js:200:7)
at Socket. (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\client.js:831:21)
at Socket.emit (node:events:517:28)
at TCP. (node:net:350:12)
Emitted 'error' event on ReadStream instance at:
at Object.cb (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\protocol\SFTP.js:3710:12)
at cleanupRequests (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\protocol\SFTP.js:2734:11)
at SFTP.push (C:\Users\mahesh\Desktop\JS\node_modules\ssh2\lib\protocol\SFTP.js:191:7)
[... lines matching original stack trace ...]
at TCP. (node:net:350:12)

@theophilusx
I'm using createReadStream because, I'm trying to get the file in base64 format.

Thanks

Hello @theophilusx
using get() method can we give destination path as S3 bucket url S3://<ingest-bucket>/<file-basename>/<filename>

something like this
sftp.get(remoteFilePath, S3://<ingest-bucket>/<file-basename>/<filename>)

I don't think there is anything more required here. Plan to close this job if I don't hear otherwise.