gpt4 book ai didi

sockets - 第二次chrome.sockets.tcp.send调用始终导致 “500 Invalid command: try being more creative”

转载 作者:行者123 更新时间:2023-12-03 11:52:04 26 4
gpt4 key购买 nike

使用chrome.sockets.tcp将FTP客户端构建为Chrome应用。

一开始,每次尝试发送密码时,我都会不断收到“500无效命令:尝试变得更有创造力”。然后我意识到无论我发送什么命令,它都会在第二条命令上返回该错误。

IE。 USER,接着是PASS,会给我错误。
FEAT,然后是USER,将给我错误。
FEAT,然后是HELP,将给我错误。

我尝试在发出第二条命令之前等待一段时间。无济于事。

chrome.app.window.create('index.html', {
id: "helloWorldID",
bounds: {
width: width,
height: height,
left: Math.round((screenWidth-width)/2),
top: Math.round((screenHeight-height)/2)
}
});


var IP = "server.com";
var PORT = 21;
var ftp_username = "user";
var ftp_password = "password";
var socketID;

function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint8Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}

function onCallback( result ){
console.log( "onCallback", result );
};

chrome.sockets.tcp.create({ persistent:false }, function(createInfo) {
socketID = createInfo.socketId;

chrome.sockets.tcp.connect( socketID, IP, PORT, onCallback);
});

chrome.sockets.tcp.onReceive.addListener(function(info) {
//console.log( "onReceive", info.socketId );
var d = ab2str( info.data );
console.log( d );

if (d.indexOf("220 ")>-1){

// send user.
console.log( "send " + ftp_username);
chrome.sockets.tcp.send( socketID, str2ab("USER "+ftp_username+"\n"), onCallback );
}
if (d.indexOf("331 ")>-1){
// send password.
console.log( "send password");
chrome.sockets.tcp.send( socketID, str2ab("PASS "+ftp_password+"\n"), onCallback );
}

});
chrome.sockets.tcp.onReceiveError.addListener(function(info) {
console.log( "onReceiveError", info );
});

});

最佳答案

您必须在ArrayBuffer中为每个字符保留1个字节,而不是两个

var buf = new ArrayBuffer(str.length); // 1 byte for each char

关于sockets - 第二次chrome.sockets.tcp.send调用始终导致 “500 Invalid command: try being more creative”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24413362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com