【问题标题】:node. - create tunnel for localhost ftp server using ngrok节点。 - 使用 ngrok 为 localhost ftp 服务器创建隧道
【发布时间】:2021-06-05 18:59:40
【问题描述】:

是否可以为使用从 localhost 运行的节点 cli 脚本创建的 ftp server 创建带有 ngrok 的隧道?

更新
我正在使用此代码,但无法启动服务器并连接

#!/usr/bin/env node

/**
 * 
 */
const path = require('path');
const ngrok = require('ngrok');
const FtpServer = require('ftp-srv');

const www = path.format({dir: __dirname, base: '/shared'})

const ftpServer = new FtpServer({
    url: 'ftp://127.0.0.1:21',
    anonymous: true,
    greeting: 'Hello user!'
});

ftpServer.on('login', (data, resolve, reject) => {
    console.log(data);
    resolve({root: www});
});

ftpServer.listen().then( () => {
    console.log('Server is running');
    ngrok.connect({proto: 'tcp', addr: 21});
});

我收到此错误

{"name":"ftp-srv","hostname":"host.local","pid":38965,"level":40,"msg":"Passive URL not set. Passive connections not available.","time":"2021-03-07T21:34:50.077Z","v":0}
{"name":"ftp-srv","hostname":"host.local","pid":38965,"level":50,"err":{"message":"listen EACCES: permission denied 127.0.0.1:21","name":"Error","stack":"Error: listen EACCES: permission denied 127.0.0.1:21\n    at Server.setupListenHandle [as _listen2] (node:net:1278:21)\n    at listenInCluster (node:net:1343:12)\n    at doListen (node:net:1480:7)\n    at processTicksAndRejections (node:internal/process/task_queues:81:21)","code":"EACCES"},"msg":"[Event] error","time":"2021-03-07T21:34:50.105Z","v":0}
Unhandled rejection Error: listen EACCES: permission denied 127.0.0.1:21
    at Server.setupListenHandle [as _listen2] (node:net:1278:21)
    at listenInCluster (node:net:1343:12)
    at doListen (node:net:1480:7)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)

我需要先启动一个节点http服务器吗?我将如何连接到具有此地址tcp://2.tcp.ngrok.io:11653 的隧道?

【问题讨论】:

  • 是的 ngrok 创建隧道并支持不同的端口转发。不过,实际上需要更多细节来回答您的问题。你想做什么?你试过什么?你最终的首选结果是什么?
  • 我会用代码更新问题。基本上我想创建一个 cli 脚本,在运行时将创建一个 ftp 服务器,该服务器可以从网络访问到拥有使用 ngrok 隧道上传/下载文件的链接的人。
  • 消息,Error: listen EACCES: permission denied 127.0.0.1:21 在我看来,您的操作系统不允许服务器侦听端口 21。这种情况并不少见。您可能需要将其移至其他端口,例如 21021 或其他任何端口
  • 你在正确的轨道上。您启动 FTP 服务器,然后将 ngrok 连接到它,指向您需要 ngrok 将流量路由到的本地端口。它不需要是 TCP21。如果您使用的是 ngrok 的免费计划,则每次设置隧道时它都会返回一个不同的地址以公开连接。

标签: node.js ngrok ftp-server


【解决方案1】:

根据您提供的错误,您的操作系统似乎不允许应用程序侦听 TCP 端口 21。这并不少见(安全原因)。我的建议是使用不同的端口,例如21021 为要列出的 FTP 服务器。服务器启动后,让ngrok 通过隧道将流量转发到该端口。

如果您使用 ngrok 的免费计划,则每次建立隧道时,该隧道的地址都会改变。所以第一次可能是tcp://2.tcp.ngrok.io:11653,下一次就改成tcp://2.tcp.ngrok.io:13859。

【讨论】:

  • 我知道 ngrok 每次分配不同的地址,我在打开提供的隧道链接时遇到了一些麻烦,我尝试使用 filezilla 但协议无法识别,也在浏览器 连接后我无法查看我配置为 root 的文件夹。有什么建议吗,在 ftp 服务器启动并运行之后,我还可以使用标准的 http 隧道吗?
  • 您不能使用 http 隧道,这不是 http 连接。您是说 FileZilla 无法打开2.tcp.ngrok.io:11653?你能在你的机器上本地连接到 ftp 服务器吗?
  • 我需要测试,我已经使用了包含协议的完整地址。如果我在 filezilla 中省略 tcp:// 协议,我会告诉你连接是否有效
  • 我无法使用 filezilla 正确连接到服务器
  • 这包括在本地运行您无法使用 filezilla 连接到 ftp 的所有内容?
猜你喜欢
  • 2017-02-21
  • 1970-01-01
  • 2019-11-12
  • 2019-12-04
  • 2015-07-13
  • 2016-01-22
  • 1970-01-01
  • 2018-05-19
  • 2019-12-14
相关资源
最近更新 更多