node.js - 使用 Node.js 套接字代码提交的 FTP 命令未处理
问题描述
我有以下使用 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'
它挂在那里。
为什么这个节目没有通过第二轮和第三轮?
解决方案
您必须使用 CRLF 终止(提交)命令:
sock.write('USER anonymous\r\n');
推荐阅读
- python - 使用列表推导从 python 函数输出多个列表
- java - 如何基于键迭代 Json 模式和值
- scala - 如何避免 SLF4J 类路径中的多个类绑定
- lansa - 如何使用 user32 SendMessage 在 Lansa 网格中获取数据
- php - 注意:未定义变量:PHP 7.1 中的 grandTotal
- python - 如何在不使用 Xpath Selenium Python 的情况下单击
- mysql - 如何获取像这个mysql查询这样的金额和字段
- java - 如何在spring data jpa for mysql数据库中一起使用一对一和一对多关系
- php - 让 nginx 将每个请求重定向到 index.php 但不下载文件
- json - Symfony - Ajax 请求更新不起作用