سلام و درود
برای انتقال فایل اطلاعات ذخیره شده روی کارت حافظه متصل به ESP32 خواستم از FTP استفاده کنم. برای این کار دو تا کتابخانه SimpleFTPServer و ESP32FtpServer را نصب کردم که با هر دو امکان وصل شدن به بورد هست ولی نمیتونم لیست فایلهای روی کارت را ببینم.
با FileZilla FTP هم امتحان کردم که باز هم اتصال برقرار میشه ولی لیست فایلها قابل مشاهده نیست. توی FileZilla مدل انتقال را تغییر دادم (هم Passive و هم Active) که نتیجه ای نداشت.
حالا با توجه به اینکه هدف فقط برداشتن فایل اطلاعات از روی حافظه و البته پاک کردن متناوب محتوای فایل است دو تا سوال دارم.
- آیا FTP انتخاب درستی برای این کار هست؟
- آیا روش دیگه ای هم هست که آسان تر هم باشه؟
خروجی روی FileZilla :
Status: Connecting to 192.168.1.2:21...
Status: Connection established, waiting for welcome message...
Status: Plain FTP is insecure. Please switch to FTP over TLS.
Status: Server does not support non-ASCII characters.
Status: Logged in
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is your current directory
Command: TYPE I
Response: 200 TYPE is now 8-bit binary
Command: PASV
Response: 227 Entering Passive Mode (192,168,1,2,195,89).
Command: MLSD
Response: 150 Accepted data connection
Response: 550 Can't open directory /
Error: Failed to retrieve directory listing
خروجی روی سریال :
Connected to Farzaman
IP address: 192.168.1.2
SD opened!
Ftp server waiting for connection on port 21
Client connected!
USER admin
Ftp server waiting for connection on port 21
Client connected!
USER admin
PASS admin
OK. Waiting for commands.
opts utf8 on
PWD
TYPE A
PASV
Connection management set to passive
Data port set to 50009
LIST
ftpdataserver client....
تشکر
#include <WiFi.h>
#include <WiFiClient.h>
#include "ESP32FtpServer.h"
#include "SD.h"
#include "FS.h"
#include "SPI.h"
const char* ssid = "Farzaman";
const char* password = "********";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP32FtpServer.h to see ftp verbose on serial
//#define FTP_DEBUG
//SD card options
#define SD_CS 5
#define SDSPEED 4000000
void setup(void){
Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.println("");
//pinMode(19, INPUT_PULLUP); //pullup GPIO2 for SD_MMC mode, you need 1-15kOm resistor connected to GPIO2 and GPIO19
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure SD is started before ftp; /////////
if (SD.begin( SD_CS, SPI, SDSPEED)) {
// if (SD_MMC.begin()) {
Serial.println("SD opened!");
ftpSrv.begin("admin","admin"); //username, password for ftp. set ports in ESP32FtpServer.h (default 21, 50009 for PASV)
}
else Serial.println("SD not opened!");
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}
