不处理使用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 anonymousrn');

相关内容

最新更新