Guest User

Untitled

a guest
Jan 2nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. app.get('/download', (req, res) => {
  2.  
  3. var config = {
  4. host: 'someHost',
  5. port: '22',
  6. username: 'user',
  7. password: 'root'
  8. }
  9. var fileName = "hello.wav"; //File Name
  10. // Connect to server
  11. sftp.connect(config).then(() => {
  12. // Get the file as a readable stream
  13. sftp.get(fileName).then((data) => {
  14. res.setHeader('Content-disposition', 'attachment; filename=' + fileName);
  15. // Set headers to download file
  16. res.setHeader('Content-Type', 'application/audio/wav');
  17. // pipe stream
  18. data.pipe(res);
  19. });
  20. });
  21. });
Add Comment
Please, Sign In to add comment