Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not fully uploaded #265

Open
ajouve opened this issue May 20, 2020 · 2 comments
Open

File not fully uploaded #265

ajouve opened this issue May 20, 2020 · 2 comments

Comments

@ajouve
Copy link

ajouve commented May 20, 2020

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
@ctfrancia
Copy link

did you ever resolve this? I get no errors while uploading but checking my ftp server it's not there

@ajouve
Copy link
Author

ajouve commented Feb 14, 2021

I change the FTP lib :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants