@@ -301,19 +301,21 @@ void ftp_run (void) {
301301 if (SOCKETFIFO_IsEmpty ()) {
302302 uint32_t readsize ;
303303 ftp_result_t result ;
304+ ftp_data .ctimeout = 0 ;
304305 result = ftp_read_file ((char * )ftp_data .dBuffer , FTP_BUFFER_SIZE , & readsize );
305- if (readsize > 0 && result != E_FTP_RESULT_FAILED ) {
306- ftp_send_data (readsize );
307- ftp_data .ctimeout = 0 ;
306+ if (result == E_FTP_RESULT_FAILED ) {
307+ ftp_send_reply (451 , NULL );
308+ ftp_data .state = E_FTP_STE_END_TRANSFER ;
309+ }
310+ else {
311+ if (readsize > 0 ) {
312+ ftp_send_data (readsize );
313+ }
308314 if (result == E_FTP_RESULT_OK ) {
309315 ftp_send_reply (226 , NULL );
310316 ftp_data .state = E_FTP_STE_END_TRANSFER ;
311317 }
312318 }
313- else {
314- ftp_send_reply (451 , NULL );
315- ftp_data .state = E_FTP_STE_END_TRANSFER ;
316- }
317319 }
318320 break ;
319321 case E_FTP_STE_CONTINUE_FILE_RX :
@@ -588,8 +590,12 @@ static void ftp_process_cmd (void) {
588590 char * bufptr = (char * )ftp_cmd_buffer ;
589591 ftp_result_t result ;
590592 uint32_t listsize ;
591- FILINFO fno ;
592593 FRESULT fres ;
594+ FILINFO fno ;
595+ #if _USE_LFN
596+ fno .lfname = NULL ;
597+ fno .lfsize = 0 ;
598+ #endif
593599
594600 ftp_data .closechild = false;
595601 // also use the reply buffer to receive new commands
@@ -887,12 +893,20 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
887893 if (FTP_UNIX_SECONDS_180_DAYS < tseconds - fseconds ) {
888894 return snprintf (dest , destsize , "%srw-rw-r-- 1 root root %9u %s %2u %5u %s\r\n" ,
889895 type , (_u32 )fno -> fsize , ftp_month [mindex ].month , day ,
896+ #if _USE_LFN
897+ 1980 + ((fno -> fdate >> 9 ) & 0x7f ), * fno -> lfname ? fno -> lfname : fno -> fname );
898+ #else
890899 1980 + ((fno -> fdate >> 9 ) & 0x7f ), fno -> fname );
900+ #endif
891901 }
892902 else {
893903 return snprintf (dest , destsize , "%srw-rw-r-- 1 root root %9u %s %2u %02u:%02u %s\r\n" ,
894904 type , (_u32 )fno -> fsize , ftp_month [mindex ].month , day ,
905+ #if _USE_LFN
906+ (fno -> ftime >> 11 ) & 0x1f , (fno -> ftime >> 5 ) & 0x3f , * fno -> lfname ? fno -> lfname : fno -> fname );
907+ #else
895908 (fno -> ftime >> 11 ) & 0x1f , (fno -> ftime >> 5 ) & 0x3f , fno -> fname );
909+ #endif
896910 }
897911}
898912
@@ -956,10 +970,10 @@ static ftp_result_t ftp_open_dir_for_listing (const char *path, char *list, uint
956970 uint next = 0 ;
957971 // "hack" to list root directory
958972 if (path [0 ] == '/' && path [1 ] == '\0' ) {
959- next += ftp_print_eplf_drive ((list + next ), (maxlistsize - next ), "SFLASH " );
973+ next += ftp_print_eplf_drive ((list + next ), (maxlistsize - next ), "flash " );
960974#if MICROPY_HW_HAS_SDCARD
961975 if (sd_disk_ready ()) {
962- next += ftp_print_eplf_drive ((list + next ), (maxlistsize - next ), "SD " );
976+ next += ftp_print_eplf_drive ((list + next ), (maxlistsize - next ), "sd " );
963977 }
964978#endif
965979 * listsize = next ;
@@ -979,11 +993,18 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
979993 uint next = 0 ;
980994 uint count = 0 ;
981995 FRESULT res ;
982- FILINFO fno ;
983996 ftp_result_t result = E_FTP_RESULT_CONTINUE ;
984-
985- /* read up to 4 directory items */
986- while (count ++ < 4 ) {
997+ FILINFO fno ;
998+ #if _USE_LFN
999+ fno .lfname = mem_Malloc (_MAX_LFN );
1000+ fno .lfsize = _MAX_LFN ;
1001+
1002+ // read up to 2 directory items
1003+ while (count < 2 ) {
1004+ #else
1005+ // read up to 4 directory items
1006+ while (count < 4 ) {
1007+ #endif
9871008 res = f_readdir (& ftp_data .dp , & fno ); /* Read a directory item */
9881009 if (res != FR_OK || fno .fname [0 ] == 0 ) {
9891010 result = E_FTP_RESULT_OK ;
@@ -992,13 +1013,17 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
9921013 if (fno .fname [0 ] == '.' && fno .fname [1 ] == 0 ) continue ; /* Ignore . entry */
9931014 if (fno .fname [0 ] == '.' && fno .fname [1 ] == '.' && fno .fname [2 ] == 0 ) continue ; /* Ignore .. entry */
9941015
995- // Add the entry to the list
1016+ // add the entry to the list
9961017 next += ftp_print_eplf_item ((list + next ), (maxlistsize - next ), & fno );
1018+ count ++ ;
9971019 }
9981020 if (result == E_FTP_RESULT_OK ) {
9991021 ftp_close_files ();
10001022 }
10011023 * listsize = next ;
1024+ #if _USE_LFN
1025+ mem_Free (fno .lfname );
1026+ #endif
10021027 return result ;
10031028}
10041029
0 commit comments