Node.js 连接到 ftp 并下载文件 [英] Node.js connect to ftp and download files

查看:36
本文介绍了Node.js 连接到 ftp 并下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我下载了这个 npm 模块来连接我的 ftp: node-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆