Node.js connect to ftp and download files

十年热恋 提交于 2019-12-07 09:26:36

问题


Hello i downloaded this npm module to connect to my ftp : node-ftps

connection class

var FTPS = require('ftps');
var ftps = new FTPS({
  host: 'myhost',
  username: 'user',
  password: 'mypw',
  protocol: 'ftp'
});

ftps.exec(function (err, res) {
  console.log();
});

how can i check if the connection was successful and how can i get all files from my path!

tryed to add an file but get an error i didn't even know if im connected


回答1:


I would advice you to try node-ftp which supports ftps too, Although node-ftps does the same work, it lacks good documentation and examples.

Checkout here,

https://github.com/mscdex/node-ftp

To setup a connection and to access it features, All you need to do is to download a node wrapper called ftp-client which is developed exclusively for the node-ftp module.

You can install this wrapper by issuing the below command,

npm install ftp-client

To initialize it use the below command,

var ftpClient = require('ftp-client'),
client = new ftpClient(config, options);

And you can find a complete example code here which will walk you through how we can connect to a server, and simultaneously upload all files from the test directory, overwriting only older files found on the server, and download files from /public_html/test directory.

https://github.com/noodny/node-ftp-client#examples

Hope this helps!



来源:https://stackoverflow.com/questions/44437453/node-js-connect-to-ftp-and-download-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!