Problem with sending short TCP packets on Electron

I’m using the library for communicating with my FTP server: https://github.com/mihaigalos/FTPino.
My code uploads small file (100 bytes) to the server every 20 seconds. (going to deep sleep after each upload)
And I am having intermittent issues with TCP socket. (problem happens approx 20% of the time).

Example: FTPClient sends “CLIENT FTPino” as the first command to the server but doesn’t get any response.
tcpdump on the server shows that packet was not received and eventually FTP connection times out.
Most of the time it happens specifically with that very first command.

When failure happens I issue few AT commands to check health of the socket:

+USOCTL: 1,0,6 // TCP socket 
OK 
CTL: 1,0,6 
+USOCTL: 1,10,4 // ESTABLISHED 
OK 
CTL: 1,10,4 
+USOCTL: 1,11,15 // 15 bytes unacknoledged 
OK 
CTL: 1,11,15 
+USOCTL: 1,1,0 // no socket errors 
OK 
CTL: 1,1,0

It seems that problem starts happening after some time. Initial attempts almost always successful.

Tried to play with socket options using AT+USOSO=1,6,1,1 - enabling “no delay” option. But nothing is going through after that.

Any other way to control TCP stack parameters? retransmissions etc?
Is it worth looking into FTP AT commands provided by u-blox and implementing FTP client using them?
Any other ideas how to fix and/or debug the problem?

I am running vsftpd server on AWS.

Snippet:

FTPClient ftp (ftpAddress, user, pass);

int callback(int type, const char* buf, int len, char* param)
{
  Serial.println(buf);
  return WAIT;
}

void modem_at(const char* command)
{
  Cellular.command(callback, (char*)NULL, 20000, command);
}

void setup()
{
    uint32_t len=100;

    Particle.disconnect();
    delay(500);

    Serial.println("Sending over ftp");

    remoteFile = System.deviceID() + "_" + Time.format(Time.now(), "%Y%m%d_%H%M%S") + ".txt";

    Serial.println("Remote filename: " + remoteFile);
    String ftp_e = ftp.send(Buf,len,remoteFile);

    Serial.print(ftp_e);
    if(0 != ftp_e.compareTo("FTP Success"))
    { // failure
      modem_at("AT+USOCTL=1,0\r\n");
      modem_at("AT+USOCTL=1,10\r\n");
      modem_at("AT+USOCTL=1,11\r\n");
      modem_at("AT+USOCTL=1,1\r\n");
      delay(1000);
      System.reset();
    }
    else
    { // success
        System.sleep(SLEEP_MODE_DEEP,  20);
    }
}

Excerpt from FTPClient.cpp:

String FTPClient::send(String &stringToWrite, String &remoteFile, TE_FTPClient_WriteMode writeMode){
        char outBuf[128];
        client.connect(server,21);
        int maxInterations = 10000; while(  (client.connected()) &&  (--maxInterations >0)  );
        
        if (!client.connected())  return "Error, cannot connect to FTP.";
        
        
        if(!readServerResponse(outBuf)) return "Error when connecting to FTP Server.";
        
        client.println("CLIENT FTPino");       if(!readServerResponse(outBuf)) return "Error when sending USER (credential username).";
        client.println("USER "+username);       if(!readServerResponse(outBuf)) return "Error when sending USER (credential username).";
        client.println("PASS "+password);       if(!readServerResponse(outBuf)) return "Error when sening PASS (credential password).";
        client.println("SYST");                 if(!readServerResponse(outBuf)) return "Error when sending SYST.";
        client.println("TYPE I");               if(!readServerResponse(outBuf)) return "Error when sending Type I.";
        client.println("PASV");                 if(!readServerResponse(outBuf)) return "Error when sending PASV.";
        char *tStr = strtok(outBuf,"(,"); // tokenizing response of server, getting ports for data transfer