How do you retrieve a file if your node express web service is on a linux server (ubuntu) and you need to download files from a windows server?
2 Valid Options:
Windows Servers do not support SFTP/SSH. There are some ways to do this (with https://winscp.net/eng/docs/guide_windows_openssh_server and https://www.npmjs.com/package/ssh2) but this requires our server administrator to install on windows and it isn't fully supported by Microsoft.
You could use FTP/FTPS. There's this package: https://github.com/Atinux/node-ftps I just wasn't able to get this to work but it should be a viable option.
How can you do this from the operating system directly instead of relying on third-party node packages?
You can use smbget (linux utility included with https://linux.die.net/man/1/smbget ) and then just use node child_process spawn to call the function.
Just replace [workgroup], [username], [password], [serveraddress], and [path] with your own information here.
The code snippet above returns a promise. So in node you could send the response to a route like this:
The response will be the actual binary for the file to download. Since this file was retrieved from a remote server, we also need to make sure we delete the local file using fs.unlinkSync().
Use res.download to send the proper headers with the response so that most modern web browsers will know to prompt the user to download the file.