node-ftp
node-ftp copied to clipboard
File not fully uploaded
Hi,
I am trying to upload a file of 116MB into a local ftp server.
const FTP = require('ftp');
const fs = require('fs')
const config = require('./config')
const ftp = new FTP();
const buffer = fs.readFileSync('/Users/ajouve/Downloads/test.bin')
ftp.once('ready', () => {
console.log('connected');
ftp.put(buffer, 'SD_Card/test1.bin', (err) => {
console.log(err);
console.log('done')
})
});
ftp.connect({ host: config.fan.ip, user: 'admin', password: 'admin' });
The put ends with no error but when I am checking the size on the ftp the file is not fully uploaded.
The logic is a little random, with the script I just set earlier it will upload between 80% and 100%, but this was just a script to debug. The normal script is doing heavy processing on the bin file generation and in this case the upload is between 5% and 10%
I tried to add a function to cut my buffer
/**
*
* @param {Buffer} buffer
* @param {number} splitSize
*/
module.exports.splitBuffer = (buffer, splitSize) => {
let i = 0;
const bufferSize = buffer.byteLength;
const buffers = [];
while(i < bufferSize) {
const start = i;
const end = i + splitSize > bufferSize ? bufferSize : i + splitSize;
buffers.push(buffer.slice(start, end));
i = end;
}
return buffers
}
and then upload it using put
for the first element and then append
but my ftp server does not support append
Append/Restart not permitted, try again
did you ever resolve this? I get no errors while uploading but checking my ftp server it's not there
I change the FTP lib :D