Skip to content

Commit

Permalink
minor changes to ftp module
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Jan 17, 2020
1 parent 38d8f7b commit 3ebe6fa
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions packages/nexrender-provider-ftp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,53 @@ const download = (job, settings, src, dest, params) => {
}

const upload = (job, settings, src, params) => {
if (!params.host) {
throw new Error('FTP Host not provided.')
}
if (!params.port) {
throw new Error('FTP Port not provided.')
}
if (!params.user) {
throw new Error('FTP Username not provided.')
}
if (!params.password) {
throw new Error('FTP Password not provided.')
}
if (!params.host) throw new Error('FTP Host not provided.')
if (!params.port) throw new Error('FTP Port not provided.')
if (!params.user) throw new Error('FTP Username not provided.')
if (!params.password) throw new Error('FTP Password not provided.')

return new Promise((resolve, reject) => {
let file;
let con;

return new Promise((resolve, reject) => {
// Read file
try{
var file = fs.createReadStream(src);
try {
file = fs.createReadStream(src);
}
catch(e){
catch(e) {
throw new Error('Cloud not read file, Please check path and permissions.')
}

file.on('error', (err) => reject(err))
var filename = path.basename(src)
const filename = path.basename(src)

// Connect to FTP Server
try{
var con = new FTP();
try {
con = new FTP();
con.connect(params);
}
catch(e){
catch(e) {
throw new Error('Cloud not connect to FTP Server, Please check Host and Port.')
}
// Put file
try{

// Put file
try {
con.put(file, filename, function(err) {
if (err) return reject(err)

if (err) {
con.end()
reject(err)

return;
}

con.end()
resolve()
});
}
catch(e){
throw new Error('Cloud not upload file, Please make sure FTP user has write permissions.')
con.end()
throw new Error('Cloud not upload file, Please make sure FTP user has write permissions.')
}

})
}

Expand Down

0 comments on commit 3ebe6fa

Please sign in to comment.