Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const router = express.Router();
- const jsftp = require("jsftp");
- const fs = require("fs");
- require("dotenv/config");
- const ftp = new jsftp({
- host: process.env.FTP_HOST,
- port: process.env.FTP_PORT,
- user: process.env.FTP_USER,
- pass: process.env.FTP_PASS,
- });
- router.post("/", (req, res) => {
- const formidable = require("formidable");
- const form = new formidable.IncomingForm();
- form.parse(req, (err, fields, files) => {
- fs.readFile(files.file.path, function (err, buffer) {
- if (err) {
- console.error(err);
- } else {
- let obj = JSON.parse(fields.obj);
- ftp.put(
- buffer,
- "public_html/uploads/" + obj.resource + "/" + obj.id,
- (err) => {
- if (!err) {
- console.log("File transferred successfully!");
- }
- console.log(err);
- }
- );
- }
- });
- res.end();
- });
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement