使用 Node 访问另一台服务器中的 FTP

Using Node to access FTP in another server

我需要在另一台服务器上访问 FTP (Ubuntu).

我的 Node.js API 从用户那里收到一张图片,然后需要使用 FTP 连接将其上传到另一台服务器。但是,如果用户文件夹不存在,我需要在发送图像之前创建文件夹。

我该怎么做?

我正在使用快速上传来获取文件:

const express       = require('express');
const upload        = require('express-fileupload');

const app = express();

app.use(upload());

app.use('/upload', async (req, res, next) => {
  console.log(req.files.image);
})

您可以使用Basic FTP,一个FTP客户端模块,并使用它的ensureDir()方法来实现“如果用户文件夹不存在,我需要创建文件夹”的需求在发送图片之前。

根据其文档:

...we make sure a remote path exists, creating all directories as necessary.

await client.ensureDir("my/remote/directory")

然后,您可以使用其 upload() 方法发送图像。