Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get('/download', (req, res) => {
- var config = {
- host: 'someHost',
- port: '22',
- username: 'user',
- password: 'root'
- }
- var fileName = "hello.wav"; //File Name
- // Connect to server
- sftp.connect(config).then(() => {
- // Get the file as a readable stream
- sftp.get(fileName).then((data) => {
- res.setHeader('Content-disposition', 'attachment; filename=' + fileName);
- // Set headers to download file
- res.setHeader('Content-Type', 'application/audio/wav');
- // pipe stream
- data.pipe(res);
- });
- });
- });
Add Comment
Please, Sign In to add comment