@mjs513, @Khoih-prog - Was working with FTP_Server_Teensy41 today to try and figure out why I was only getting partial transfers when downloading from the T4.1 to the PC using gFTP or Filezilla. Turns out the failure was in the doRetrieve() function:
Code:
bool FtpServer::doRetrieve()
{
if ( ! dataConnected())
{
file.close();
return false;
}
int16_t nb = file.read( buf, FTP_BUF_SIZE );
if ( nb > 0 )
{
data.write( buf, nb );
bytesTransfered += nb;
return true;
}
closeTransfer();
return false;
}
The data.write() buffer was being overwritten before the transfer was complete. That's why the files were coming up smaller on the client side than the original transfer size. I changed the doRetrieve() function to this:
Code:
bool FtpServer::doRetrieve()
{
if ( ! dataConnected())
{
file.close();
return false;
}
// Find available space in data.write() buffer.
int spaceLeft = data.availableForWrite();
// Get remaining bytes to read from file.
int32_t leftToXfer = file.available();
if (spaceLeft <= 0) {
return true; // Return true if no space available.
}
// Calculate read size.
// Base the amount to read on the space available in the
// data.write() buffer.
if(leftToXfer) {
int32_t nb = file.read( buf,(spaceLeft <= FTP_BUF_SIZE) ? spaceLeft : FTP_BUF_SIZE);
data.write(buf, nb);
bytesTransfered += nb;
return true;
}
closeTransfer();
return false;
}
The size of the transfer will always be equal to spaceLeft if it is less than or equal to FTP_BUF_SIZE.
Tested this with QNEthernet and NativeEthernet. FTP_BUF_SIZE gave the best transfer speeds. ~2MBs.
@Khoih-prog will issue a PR.