1

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.

ftp.ls(".", function(err, res) { res.forEach(function(file) { console.log(file.name); //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.'); else console.log('File copied successfully!'); }); 

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, your suggestion solve my problem. I am simply using res.download(path);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.