ParticleFTPClient slower than expected

Hey everyone,

I’m using ParticleFTPClient library to send a JSON file I’ve created to an ec2 instance. The file is typically 2 MB in size. My experience has been that this takes about 60 - 90 seconds for upload. This seems out of the norm… heres a snippet in how I’m reading the file into the stor -

   // Set the file type to ASCII
    ftp.type("A"); 
    // Initiate an upload
    ftp.stor(fileName);
 
    
    Serial.println("attempting to ftp file");

    // read from the file until there's nothing else in it:
    int data;
    while ((data = myFile.read()) >= 0) {
        Serial.write(data);
        ftp.data.write(data);
    }
    ftp.data.flush();
    bool success;
    success = Particle.publish("FTP Upload Successful");
    
    if (!success) {
        Serial.println("FTP Transfer was not successful");
    }

    // Call finish when you are done uploading. You may expect a timeout here.
    if (!ftp.finish()) {
        Serial.println("Couldn't stop file upload");
        myFile.close();
    }
    //inConnectionLoop = false;
    if (!myFile.remove()) {
        Serial.println("Error file.remove");
        myFile.close();
    }``

I imagine that this has something to do with reading each byte in one at a time. Any ideas on how to decrease the upload times?

Thanks in advance!

This loop reads one byte at a time and then sends one FTP TCP packet with just that byte in it. You should at least write a loop that read 512 bytes into a buffer and then sends that chuck all at once.

2 Likes

thanks @bko