cancel
Showing results for 
Search instead for 
Did you mean: 

File transfer through FTP getting inconsistent. am I did anything wrong on code?

Sayooj M
Associate

I am using STM32F4, and i am able to transmit files through FTP using netconn.I will read the files from SD card (each time 256 bytes ) and I will send to server. If I am transmitting 10 files, few of them are corrupted, but even though the file size became same. The file start get corrected from the first byte of a packet(some times it will be 10th or 15th packet or any random packet - some times no failure).

FTP send function is here.

FunctionStatus FtpSendFile(char *filename, char *Serverfilename)

{

 sprintf(file_upload,"STOR WRITE.txt\r\n");

 err_t err12=netconn_write(conn_ftpcmd,file_upload,(int)strlen(file_upload),NULL);  

 netconn_recv(conn_ftpcmd,&ftp_receive_netbuf);                  

 netbuf_data(ftp_receive_netbuf,(void**)&ftpbuf,&receiverbef_len);

 netbuf_delete(ftp_receive_netbuf);

 while(remainingdatatoread)

 {   

  datatoread = remainingdatatoread > maxnoofbytestoreadatatime ? maxnoofbytestoreadatatime : remainingdatatoread;

  fresult = f_read(&filponter, RdData,datatoread, &testbyteread);

  if(fresult)

   return FILE_READING_FAILURE;

  totalbytes = totalbytes + testbyteread;

  f_lseek(&filponter, totalbytes);

  remainingdatatoread = remainingdatatoread - testbyteread;

  err12=netconn_write(newconn,RdData,testbyteread,NULL);            // Sending data into the file.

  if(err12)

   return FILE_SENDING_TO_SERVER_FAILURE;

  HAL_Delay(1);

  memset(RdData,'\0',testbyteread);

 }

 f_close(&filponter);

 return FILESENDSUCCESSFULLY;

}

0 REPLIES 0