Javascript Node.js 连接到 ftp 并下载文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44437453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:31:15  来源:igfitidea点击:

Node.js connect to ftp and download files

javascriptnode.jsdownloadftpconnection

提问by Alex

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

你好,我下载了这个 npm 模块来连接到我的 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

尝试添加文件但收到错误我什至不知道我是否已连接

回答by David R

I would advice you to try node-ftpwhich supports ftpstoo, Although node-ftpsdoes the same work, it lacks good documentation and examples.

我建议您也尝试使用node-ftp哪些支持ftps,虽然node-ftps可以完成相同的工作,但缺乏良好的文档和示例。

Checkout here,

在这里结帐,

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

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-clientwhich is developed exclusively for the node-ftpmodule.

要设置连接并访问它的功能,您需要做的就是下载一个名为的节点包装器ftp-client,该包装器专为该node-ftp模块开发。

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 testdirectory, overwriting only older files found on the server, and download files from /public_html/test directory.

您可以在此处找到完整的示例代码,它将引导您了解我们如何连接到服务器,同时上传test目录中的所有文件,仅覆盖服务器上找到的旧文件,并从/public_html/test directory.

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

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

Hope this helps!

希望这可以帮助!