FTP 使用 Node.js 提交的命令未处理套接字代码
FTP command submitted with Node.js Socket code is not processed
我有以下 FTP 使用 telnet 的会话:
$ 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');
我有以下 FTP 使用 telnet 的会话:
$ 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');