我拥有Minecraft服务器,当时正在研究解决管理员滥用问题。而且我真的不想遍历无休止的聊天记录来查找谁在作弊以及以何种方式作弊。我当时正在开发一个Discord机器人,该机器人会自动从常规聊天中过滤掉命令并确定谁发送了这些命令。我已经覆盖了那部分。但是,我需要有关从远程站点获取文本文件的帮助。当前,我使用一个名为FileZilla的程序来编辑服务器上的FTP文件,它可以完美运行。我发现无法将远程站点放在我的计算机上,并且我正在寻找一种解决方案,以某种方式使用discord bot中的javascript访问远程站点。我具有访问远程站点的凭据,只需要代码即可在不和谐的bot中访问它,因为它可以访问本地文件,但我不确定如何访问服务器。
我必须进入此站点才能尝试问题https://github.com/theophilusx/ssh2-sftp-client
如果使用的是Node.js,则可以使用ftp npm package。完成npm install ftp
之后,您可以使用:
var Client = require('ftp');
function getFtpFile(fileName, callback) {
c.on('ready', function () {
let chunks = [];
c.get(fileName, function (err, stream) {
if (err) {
callback(null, err);
} else {
stream.on('data', chunk => chunks.push(chunk));
stream.on('end', () =>
callback(Buffer.concat(chunks).toString('utf8'), null));
}
});
});
}
var c = new Client();
getFtpFile('your-file-name-here', (data, err) => {
// The following code is called after the file text is fetched.
if (err) {
return; // Error, handle it in the application
}
// data is the string you want.
// also, you might want to call c.end()
// here to close the ftp connection.
})
c.connect({
'host': 'ftp.example.com',
'port': 21,
'user': 'username',
'password': 'password'
});
如果data
字符串太大,则可能导致内存问题。可以通过多种方法解决此问题,但是由于您没有提供有关如何过滤数据的信息,因此,我将做得更好。
最后,请原谅任何错误,我无法测试代码。请发表评论,我会解决所有问题。