mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 243 forks source link

Error: STOR failed: Could not create data connection. #251

Open AlejandroMataGuillen opened 5 years ago

AlejandroMataGuillen commented 5 years ago

Hi, I have the following code, basically what I need to do is go over the files array and for every file on the array upload over ftp, I tried a lot of ways to do it, sometimes work but mos of the times give that error: '{ Error: STOR failed: Could not create data connection. at makeError (/Users/alejandro/Documents/OneWorld/owi-service/node_modules/ftp/lib/connection.js:1067:13) at Parser. (/Users/alejandro/Documents/OneWorld/owi-service/node_modules/ftp/lib/connection.js:113:25) at Parser.emit (events.js:189:13) at Parser._write (/Users/alejandro/Documents/OneWorld/owi-service/node_modules/ftp/lib/parser.js:59:10) at doWrite (_stream_writable.js:410:12) at writeOrBuffer (_stream_writable.js:394:5) at Parser.Writable.write (_stream_writable.js:294:11) at TLSSocket.ondata (/Users/alejandro/Documents/OneWorld/owi-service/node_modules/ftp/lib/connection.js:273:20) at TLSSocket.emit (events.js:189:13) at addChunk (_stream_readable.js:284:12) code: 550 }'

Is there an example or some workaround for that specific case, like I said before sometimes the 4 files got uploaded but some other times fails and none of the files are uploaded, and some other time only 2 or 3.

`function ftpUpload(config, local, remote) { const c = new Client(); c.on('ready', () => { c.put(local, remote, error => { if (error) console.log(error); console.log('File uploaded'); c.end(); }); }); c.connect(config); }

function uploadFiles() { const files = [ 'EXAMPLE_AGS_15_000_20151110.txt', 'EXAMPLE2_AGS_15_000_20151110.txt', 'EXAMPLE3_AGS_15_000_20151110.txt', 'EXAMPLE4_AGS_15_00020151110.txt', ]; files.forEach(file => { let filename = file.replace('.txt', '').split(''); filename.pop(); filename = ${filename.join('_')}_${moment().format('YYYYMMDD')}.txt;

const dataToSend = fs.readFileSync(`${filesDir}${file}`).toString();

ftpUpload(options, `${filesDir}${file}`, `${destinationDir}${filename}`);

}); }

uploadFiles();`

Thanks