0

I want to upload my files in the "src" folder whenever a user clicks on a specific button on the webpage. I am using the "ftp-deploy" NodeJS package but I don't know how to connect that package with ReactJS. I read somewhere that I have to connect using Express and assign the ftp.js file (shown below) to an API so when a user clicks on a button, it will call that API.

If anyone has done similar work before, please give me a direction about what I should do next. Thank you.

Links to the "ftp-deploy" package: https://www.npmjs.com/package/ftp-deploy

The code below is the content inside my ftp.js

var Deploy = require('ftp-deploy');
var ftpDeploy = new Deploy();

var config = {
    host: "host",
    user: "user",
    password: "password",
    port: 21,
    localRoot: __dirname + '/src',
    remoteRoot: '/',
    include: ['*'],
    deleteRemote: true
}
ftpDeploy.deploy(config, function (err, res) {
    if (err) console.log(err)
    else console.log('finished:', res);
});
ftpDeploy.on("uploading", function (data) {
    data.totalFilesCount;
    data.transferredFileCount;
    data.filename;
});
ftpDeploy.on("uploaded", function (data) {
    console.log(data);
});
ftpDeploy.on("log", function (data) {
    console.log(data);
});
ftpDeploy.on("upload-error", function (data) {
    console.log(data.err);
});
  • assuming you are using react as a webpage and not electron - your frontend react app will need to send an HTTP request of some kind, or a message via websocket to a nodejs server. your backend server will process the http request or websocket command and run your FTP commands. React is frontend code, ftp is backend... – alilland Sep 07 '20 at 00:52

0 Answers0