Node.js连接到ftp并下载文件 [英] Node.js connect to ftp and download files
问题描述
您好,我下载了此npm模块以连接到我的ftp:节点ftps
Hello i downloaded this npm module to connect to my ftp : node-ftps
连接类
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
推荐答案
我建议您尝试使用 node-ftp
,它也支持 ftps
,尽管 node-ftps
做同样的工作,缺少好的文档和示例。
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.
在此处结帐,
https://github.com/mscdex/node-ftp
要建立连接并访问其功能,您需要做的就是下载一个名为 ftp-client的节点包装器
专为 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);
您可以在此处找到完整的示例代码,它将引导您逐步了解如何连接服务器,同时从 test
目录上传所有文件,仅覆盖服务器上找到的较旧文件,并从 / public_html / test目录下载文件
。
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
希望这会有所帮助!
这篇关于Node.js连接到ftp并下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!