Sonu Sen Sonu Sen - 1 year ago 165
Node.js Question

file download from ftp server in nodejs

I have web application where on button click invoking REST API which fetch list of files available in ftp server and displayed in div with hyperlink on file name as below.

for this I am using jsftp module.".", function(err, res) {
res.forEach(function(file) {
//logic to display in div

I have another REST API for download file from FTP server which invoked on file name click present in div but it is downloaded in local directory where web application deploy and not in users system with below code, but I want when user click on file name that file should download in users system or computer. How I can achieve this.

ftp.get('remote/file.txt', 'local/file.txt', function(hadErr) {
if (hadErr)
console.error('There was an error retrieving the file.');
console.log('File copied successfully!');

Answer Source

Now that the file is on your machine you will want to actually server the file to the client when they click on the link. Using res.write something like: res.write(file, 'binary');

Here are some concepts that you'll find useful: Node.js send file to client