我正在尝试使用node-ftp从GoDaddy的ftp服务器下载zip文件,但是node-ftp在其连接功能中默认将空密码更改为"anonymous@"。如何仅使用用户名而不使用密码连接到他们的FTP服务器?
扫描源代码后,他们将密码更改为anonymous@:https://github.com/mscdex/node-ftp/blob/master/lib/connection.js#L92
const FTPClient = require('ftp');
const fs = require('fs');
const extract = require('extract-zip');
let getGoDaddyAuctionListings = () => {
let config = {
directory: "/tmp/",
file: "auctions_ending_today.json.zip"
};
config.filePath = config.directory + config.file;
let c = new FTPClient();
c.on('ready', () => {
c.get(config.file, (err, stream) => {
if (err) throw err; //todo: change to handleError function
stream.once('close', () => { c.end(); });
stream.pipe(fs.createWriteStream(config.filePath));
extract(config.filePath, {dir:config.dir}, (err) => {
if (err) throw err;
});
})
});
c.connect({
host: 'ftp.godaddy.com',
user: 'auctions',
password: ' '
});
};
getGoDaddyAuctionListings();
> node godaddyAuctions.js
events.js:174
throw er; // Unhandled 'error' event
^
Error: Login incorrect.
at makeError (C:Usersjimpbn-findernode_modulesftplibconnection.js:1067:13)
at Parser.<anonymous> (C:Usersjimpbn-findernode_modulesftplibconnection.js:113:25)
at Parser.emit (events.js:189:13)
at Parser._write (C:Usersjimpbn-findernode_modulesftplibparser.js:59:10)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
at Parser.Writable.write (_stream_writable.js:299:11)
at Socket.ondata (C:Usersjimpbn-findernode_modulesftplibconnection.js:273:20)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:288:12)
Emitted 'error' event at:
at Object.reentry [as cb] (C:Usersjimpbn-findernode_modulesftplibconnection.js:192:14)
at Parser.<anonymous> (C:Usersjimpbn-findernode_modulesftplibconnection.js:113:22)
at Parser.emit (events.js:189:13)
[... lines matching original stack trace ...]
at addChunk (_stream_readable.js:288:12)
此代码:
this.options.password = options.password ||
options.password === '' ? options.password : 'anonymous@';
允许空密码,但您没有给它一个空密码:
password: ' '
您已将密码设置为空格。这样做:
password: ''
它应该工作正常。