【问题标题】:FTP command submitted with Node.js Socket code is not processed使用 Node.js 套接字代码提交的 FTP 命令未处理
【发布时间】:2020-03-31 08:54:47
【问题描述】:

我有以下使用 telnet 的 FTP 会话:

$ telnet ftp.fsn.hu 21
Trying 195.228.252.133...
Connected to ftp.fsn.hu.
Escape character is '^]'.
220 ftp.fsn.hu FTP server (Version 6.00LS) ready.
USER anonymous
331 Guest login ok, send your email address as password.
PASS joe@example.com
230 Guest login ok, access restrictions apply.

我试图自动化这个:

var net = require('net');

var sock = net.Socket();

var regex220 = /^220/;

var regex331 = /^331/;

var regex230 = /^230/;

sock.on('data', function (buffer)
  { console.log('data received:\n' + buffer);

    if (buffer.toString().match(regex220) !== null)
    {
      sock.write('USER anonymous');
      console.log("sent: 'USER anonymous'");
    } else if (buffer.toString().match(regex331) !== null)
    {
      sock.write('PASS joe@example.com');
      console.log("sent: 'PASS joe@example.com'");
    } else if (buffer.toString().match(regex230) !== null)
    {
      console.log('LOGGED IN');
    }
  });

sock.connect(21, 'ftp.fsn.hu');

在 Fedora 32 和 Node.js 12.16.1 上运行我得到

$ node fsn.js
data received:
220 ftp.fsn.hu FTP server (Version 6.00LS) ready.

sent: 'USER anonymous'

它挂在那里。

为什么这个节目没有通过第二轮和第三轮?

【问题讨论】:

  • 哦,你是对的。

标签: node.js sockets events ftp


【解决方案1】:

您必须使用 CRLF 终止(提交)命令:

sock.write('USER anonymous\r\n');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-12
    • 2020-02-05
    • 2014-03-18
    • 1970-01-01
    • 2016-07-28
    • 2015-06-05
    • 2020-02-19
    • 1970-01-01
    相关资源
    最近更新 更多