/ / दूरस्थ सर्वर पर विशिष्ट फ़ोल्डर multer-ftp फ़ाइलों को कैसे अपलोड करें? - node.js, एक्सप्रेस, फ़ाइल अपलोड, मल्टर

रिमोट सर्वर पर विशिष्ट फ़ोल्डर multer-ftp पर फ़ाइलों को कैसे अपलोड करें? - node.js, एक्सप्रेस, फ़ाइल अपलोड, मल्टर

इस कोड का उपयोग करके मैं दूरस्थ सर्वर पर फ़ाइलों को भेजने का प्रयास करता हूं:

var upload = multer({
storage: new ftpStorage({
basepath: "/uploads/",

ftp: {
host: "samplehost.com",
secure: false, // enables FTPS/FTP with TLS
user: "login",
password: "password"
}
})
});

लेकिन हमेशा रूट निर्देशिका में फ़ाइल को सहेजें, अपलोड में नहीं, मैं इसे कैसे ठीक कर सकता हूं?

उत्तर:

जवाब के लिए 0 № 1

Multer-ftp के बजाय, multer-sftp का उपयोग कर दूरस्थ सर्वर पर फ़ाइलों को अपलोड करना आसान और लचीला तरीका है। हम भी फ़ाइलों को रिमोट सर्वर पर अपलोड कर सकते हैं एसपीपी, एसएसएच तकनीक नोड जेएस में।

कार्य कोड:

exports.newFileUpload =  function(req , res , next){

// sftp settings
var storage = sftpStorage({
sftp: {
host: "hostname",
port: 22,
username: "username",
password: "password"

},
destination: function (req, file, cb) {
cb(null, "images/") // designation folder in host
},
filename: function (req, file, cb) {
// file name settings
cb(null, file.fieldname + "-" + Date.now())
}
})

var upload = multer({ storage: storage }).array("file");

upload(req,res,function(err){
logger.debug(JSON.stringify(req.body));
logger.debug(JSON.stringify(req.files));
if(err){
logger.debug("Error Occured", JSON.stringify(err));
res.json({error_code:1,err_desc:err});
} else{
logger.debug("Files uploaded successfully");
res.json({error_code:0,err_desc:null});
}
});
}

नोट: दूरस्थ सर्वर में "multer-sftp" पोर्ट नंबर 22 का उपयोग करते समय।

आधिकारिक दस्तावेज़ीकरण multer-SFTP

आशा करता हूँ की ये काम करेगा !