ESP8266
[ESP8266] WiFi FTP Server with SD-Card[4] (디렉토리 읽기 개선)
트라이문
2017. 2. 13. 11:07
ESP8266 FTP 서버에서 파일을 전송을 하던지 PC에서 FTP 서버로 전송을 하면
ESP8266 의 디렉토리가 몇개씩 사라지는 현상이 있어서 원인을 한참 찾다가 고쳐졌습니다.
정확한 원인은 잘 모르겠고, SD Card 에서 디렉토리를 읽어서 보여줄 때,
함수를 1개(rewindDirectory) 더 추가해야 이 현상이 없어졌습니다.
어쩌면 SPIFFS 메모리에서는 이런 현상이 안나타날 지도 모르겠습니다.
제가 SPIFFS 메모리로 된 FTP 서버 프로그램을 SD 카드용으로 바꿔서 여러가지 오동작이 많이 발생하는 것 같습니다.
FTP 서버에서 디렉토리를 새로고치는 명령이 "MLSD" 이므로
ESP8266FtpServer.ccp 의 processCommand 함수에서 "MLSD" 명령을 처리하는 부분을 수정하면 됩니다.
수정한 코드는 다음과 같습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | // // MLSD - Listing for Machine Processing (see RFC 3659) // else if( ! strcmp( command, "MLSD" )) { if( ! dataConnect()) client.println( "425 No data connection MLSD"); else { client.println( "150 Accepted data connection"); uint16_t nm = 0; File dir=SD.open(cwdName); File entry; dir.rewindDirectory(); char dtStr[ 15 ]; while(1) { entry = dir.openNextFile(); if (!entry) break; String fn,fs; fn = entry.name(); fs = String(entry.size()); data.println( "Type=file;Size=" + fs + ";"+"modify=20000101160656;" +" " + fn); nm ++; } client.println( "226-options: -a -l"); client.println( "226 " + String(nm) + " matches total"); } data.stop(); entry.close(); } | cs |
SD.open() 함수 다음에 rewindDirectory(); 함수를 사용하면 됩니다.