如何连接到只有用户名但没有密码的GoDaddy的FTP服务器?

时间:2019-07-18 03:09:40

标签: node.js reactjs npm ftp node-ftp

我正在尝试使用node-ftp从GoDaddy的ftp服务器下载一个zip文件,但是在默认情况下,node-ftp的连接功能会将空密码更改为“匿名@”。如何仅使用用户名而不使用密码连接到他们的FTP服务器?

扫描了源代码,他们将密码更改为匿名@,网址为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:\Users\jim\pbn-finder\node_modules\ftp\lib\connection.js:1067:13)
    at Parser.<anonymous> (C:\Users\jim\pbn-finder\node_modules\ftp\lib\connection.js:113:25)
    at Parser.emit (events.js:189:13)
    at Parser._write (C:\Users\jim\pbn-finder\node_modules\ftp\lib\parser.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:\Users\jim\pbn-finder\node_modules\ftp\lib\connection.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:\Users\jim\pbn-finder\node_modules\ftp\lib\connection.js:192:14)
    at Parser.<anonymous> (C:\Users\jim\pbn-finder\node_modules\ftp\lib\connection.js:113:22)
    at Parser.emit (events.js:189:13)
    [... lines matching original stack trace ...]
    at addChunk (_stream_readable.js:288:12)

1 个答案:

答案 0 :(得分:0)

此代码:

this.options.password = options.password ||
    options.password === '' ? options.password : 'anonymous@';

允许输入一个空密码,但您不能给予一个空密码:

password: ' '

您已将密码设置为空格。这样做:

password: ''

它应该可以正常工作。