I\'m trying to upload the files to remote server using multer-sftp in node js. since i\'m following the official docs npm multer-sftp. Previously i\'ve uploading the files t
For Your Error, there are two possibilities
Uploading Files to remote server using multer-sftp
is easy and flexible way.
also we can upload the files to remote server with scp, ssh techniques in node js.
Working Code:
exports.newFileUpload = function(req , res , next){
var storage = sftpStorage({
sftp: {
host: 'hostname',
port: 22,
username: 'username',
password: 'password'
},
destination: function (req, file, cb) {
cb(null, 'images/')
},
filename: function (req, file, cb) {
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});
}
});
}
Note: When using 'multer-sftp' port no 22 is open in remote server.
Hope it helps !