【问题标题】:How to connect to FTPS server in node using basic-ftp module如何使用basic-ftp模块连接到节点中的FTPS服务器
【发布时间】:2019-12-13 05:13:41
【问题描述】:

我正在使用https://www.npmjs.com/package/basic-ftp基本的ftp包连接到ftps服务器。我尝试了我的其他扩展,但无法连接到 ftps 服务器 下面是我的代码

const ftp = require("basic-ftp")

example();

async function example() {
    const client = new ftp.Client()
    client.ftp.verbose = true
    try {
        await client.access({
            host: "ftp.xxxx.xxxxx",
            user: "xxxx@xxxx.xx",
            password: "xxxxxxx",
            secure :true
        })
        await client.ensureDir("/my/remote/directory")
        console.log(await client.list())
        await client.uploadFrom("temp/readme.txt", "readme.txt")
       // await client.downloadTo("README_COPY.md", "README_FTP.md")
    }
    catch(err) {
        console.log(err)
    }
    client.close()
}

但给我一个错误

Connected to xxx.xxx.xx.xxx:21
< 220 Service ready for new user.
Login security: No encryption
> USER xx@xxx.xx
< 331 User name okay, need password for xxxx@xxx.xx.
> PASS ###
< 530 Box: Smartest Energy does not allow regular FTP; use FTPS instead. (Both "
explicit" and "implicit" FTPS are supported.)
{ FTPError: 530 Box: Smartest Energy does not allow regular FTP; use FTPS instea
d. (Both "explicit" and "implicit" FTPS are supported.)
    at FTPContext._onControlSocketData (D:\node\basicftp\node_modules\basic-ftp\
dist\FtpContext.js:276:39)
    at Socket.socket.on.data (D:\node\basicftp\node_modules\basic-ftp\dist\FtpCo
ntext.js:121:44)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:265:13)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) name
: 'FTPError', code: 530 }

请帮忙 提前致谢

【问题讨论】:

    标签: node.js ftps ftp-server


    【解决方案1】:

    您需要连接Explicit FTPS over TLS。 要通过 tls 连接到 ftps,您需要传递以下选项:

    const fs = require('fs');
    
    async function example() {
        const client = new ftp.Client()
        client.ftp.verbose = true
        try {
        const secureOptions = {
      // Necessary only if the server requires client certificate authentication.
      key: fs.readFileSync('client-key.pem'),
      cert: fs.readFileSync('client-cert.pem'),
    
      // Necessary only if the server uses a self-signed certificate.
      ca: [ fs.readFileSync('server-cert.pem') ],
    
      // Necessary only if the server's cert isn't for "localhost".
      checkServerIdentity: () => { return null; },
    };
            await client.access({
                host: "ftp.xxxx.xxxxx",
                user: "xxxx@xxxx.xx",
                password: "xxxxxxx",
                secure :true,
    secureOptions : secureOptions
            })
            await client.ensureDir("/my/remote/directory")
            console.log(await client.list())
            await client.uploadFrom("temp/readme.txt", "readme.txt")
           // await client.downloadTo("README_COPY.md", "README_FTP.md")
        }
        catch(err) {
            console.log(err)
        }
        client.close()
    }
    

    【讨论】:

    • 您按要求指定了证书?并在选项中添加了secureOptions标志对吗?
    • 您确定您指定了要使用的证书的正确路径吗?
    • 是的。在选项中添加了 secureOptions 标志。当我使用 filezilla 连接时,不需要证书,所以我没有提供。只保留 checkServerIdentity: () => { return null; }, const secureOptions 中的选项
    • 我建议尝试以下库:npmjs.com/package/ftps
    • 如何生成这些文件 1)server-cert.pem 2) client-cert.pem 3)client-key.pem
    猜你喜欢
    • 2016-07-18
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 2012-05-16
    • 1970-01-01
    相关资源
    最近更新 更多