Giter Site home page Giter Site logo

esp32_ftpclient's People

Contributors

blackcodetavern avatar ldab avatar spyder0069 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32_ftpclient's Issues

FTP error: Offline

I read other issues about this error but I can't figure out what my problem. My own code didn't work so I create a new basic project (I'm using PlatformIO) from the example "upload_image". Then I followed this tutorial from youtube that implements a local FTP server with Filezilla Server. My code now is

/******************************************************************************
ESP32-CAM remote image access via FTP. Take pictures with ESP32 and upload it via FTP making it accessible for the outisde network. 
Leonardo Bispo
July - 2019
https://github.com/ldab/ESP32_FTPClient
Distributed as-is; no warranty is given.
******************************************************************************/
#include "Arduino.h"
#include <WiFi.h>
#include <WiFiClient.h> 
#include <ESP32_FTPClient.h>
#include "octocat.h"

#define WIFI_SSID "mywifissid"
#define WIFI_PASS "mywifipassword"

char ftp_server[] = "192.168.1.7";
char ftp_user[]   = "esp32";
char ftp_pass[]   = "myftppassword";

// you can pass a FTP timeout and debbug mode on the last 2 arguments
ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);

void setup()
{
  Serial.begin( 115200 );

  WiFi.begin( WIFI_SSID, WIFI_PASS );
  
  Serial.println("Connecting Wifi...");
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println("");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  ftp.OpenConnection();

  // Get directory content
  ftp.InitFile("Type A");
  String list[128];
  ftp.ChangeWorkDir("/public_html/zyro/gallery_gen/");
  ftp.ContentList("", list);
  Serial.println("\nDirectory info: ");
  for(int i = 0; i < sizeof(list); i++)
  {
    if(list[i].length() > 0)
      Serial.println(list[i]);
    else
      break;
  }

  // Make a new directory
  ftp.InitFile("Type A");
  ftp.MakeDir("my_new_dir");

  // Create the new file and send the image
  ftp.ChangeWorkDir("my_new_dir");
  ftp.InitFile("Type I");
  ftp.NewFile("octocat.jpg");
  ftp.WriteData( octocat_pic, sizeof(octocat_pic) );
  ftp.CloseFile();

  // Create the file new and write a string into it
  ftp.InitFile("Type A");
  ftp.NewFile("hello_world.txt");
  ftp.Write("Hello World");
  ftp.CloseFile();

  ftp.CloseConnection();
}

void loop()
{

}

The output of the code every time is

ets Jun  8 2016 00:22:57



rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:2

load:0x3fff0018,len:4

load:0x3fff001c,len:1044

load:0x40078000,len:10124

load:0x40080400,len:5828

entry 0x400806a8

Connecting Wifi...

........

IP address: 192.168.1.20

Connecting to: 192.168.1.7

FTP error: Offline
Send USER

FTP error: Offline
Send PASSWORD

FTP error: Offline
Send SYST

FTP error: Offline
Send TYPE

FTP error: Offline
Send CWD

FTP error: Offline
Send MLSD

FTP error: Offline

Directory info: 

Send TYPE

FTP error: Offline
Send MKD

FTP error: Offline
Send CWD

FTP error: Offline
Send TYPE

FTP error: Offline
Send STOR

FTP error: Offline
Writing

FTP error: Offline
Close File

Send TYPE

FTP error: Offline
Send STOR

FTP error: Offline
Write File

FTP error: Offline
Close File

Connection closed

I've tryed to connect with other FTP clients to my local server and it works. I read in the other similar issues that the problem may be due the server side configuration but I'm wondering why with other clients works.

Server does not seem to like change directory command

I am running vsftpd server on a linux desktop. I can connect to it and run commands successfully using a raspberry pi.
I am using the upload example program on an esp32. The esp32 connects but the server is choking on the change directory command.
Here is the output from the monitor:
IP address: 192.168.1.10
Connecting to: 192.168.1.8
Command connected
Send USER
Send PASSWORD
Send SYST
Send TYPE
Type A
Send PASV
Data port: 40313
Data connection established
FTP error: 550 Failed to change directory.

Send MLSD
FTP error: 550 Failed to change directory.

Directory info:
Send TYPE
FTP error: 550 Failed to change directory.

Send STOR
FTP error: 550 Failed to change directory.

Writing
FTP error: 550 Failed to change directory.

Close File
Connection closed

Just wondering if you might have some ideas I can try.

Thank you.

Enhancement request

Thanks for library. Please, integrate with TinyGSM too.
It is would be wonderful to get connected to ftp server by GSM network.

FTP PORT

Greetings,
I'm sorry to bother you.
I have a problem, I can't understand how the management of the FTP access port works.
If I try to write:
ESP32_FTPClient ftp (FTP_SER, 2201, FTP_USR, FTP_PWD, 5000, 2);
I get:

Connecting to: ftp.mw-net.it
Command connected
Send USER
Send PASSWORD
FTP error: Offline
Send SYST

If I write:
ESP32_FTPClient ftp (FTP_SER, 21, FTP_USR, FTP_PWD, 5000, 2);
I have no access problems.
Can you help me solve the problem?
Thanks for the kind cooperation.

Trying to upload a picture, ESP32 Cam -> local ftp server

Hello there I am trying to upload a picture from the ESP32 Cam module to a local ftp server I have running. I managed to get the example upload sketch working and successfully uploaded the octocat.jpg picture so things on the ftp/credential side seem to be fine.

EDIT: I also managed to get the proper filenames over and the files with correct filenames are being generated however they are empty or very small.

I am suspecting things are breaking in these lines as I was getting multiple compile errors until it compiled but unfortunately noticed a Guru Meditation Error and a memory dump following it:

This is how the picture is taken:
// Take Picture with Camera
fb = esp_camera_fb_get();
if(!fb) {
Serial.println("Camera capture failed");
return;
}

File file = fs.open(path.c_str(), FILE_WRITE);
if(!file){
Serial.println("Failed to open file in writing mode");
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.printf("Saved file to path: %s\n", path.c_str());
EEPROM.write(0, pictureNumber);
EEPROM.commit();
}
file.close();

This is how I am trying to send it and Im expecting the problem to be hidden here:
// Create the new file and send the image
ftp.InitFile("Type I");
ftp.NewFile(path.c_str());
ftp.WriteData( fb->buf, sizeof(fb->len) ); //<- expecting a problem here
ftp.CloseFile();

In general I am trying to combine this sketch and implement ftp functionality so that a copy of each file is sent to an ftp server.

Any help on this is appreciated as I am quite lost at the moment

FTP error: Offline

I opend a new issue like you told me:
Hey, i have the same issue. But my FTP Log says, that the ESP32 opend a session. But the same error is displayed.

/*
 * ESP32cam_ftp
 * Blog: http://www.gsampallo.com/blog/?p=686
 * Twitter: @gsampallo.com
 */
#include "esp_camera.h"
#include "soc/soc.h"           // Disable brownour problems
#include "soc/rtc_cntl_reg.h"  // Disable brownour problems
#include "driver/rtc_io.h"
#include <WiFi.h>
#include <WiFiClient.h>   
#include "ESP32_FTPClient.h"

#include <NTPClient.h> //For request date and time
#include <WiFiUdp.h>
#include "time.h"

char* ftp_server = "192.168.0.10";
char* ftp_user = "test";
char* ftp_pass = "test";
char* ftp_path = "/timelapes/";

const char* WIFI_SSID = "";
const char* WIFI_PASS = "";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", (-3600*3), 60000);

ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);

// Pin definition for CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

camera_config_t config;

void setup() {
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
 
  Serial.begin(115200);

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  
  Serial.println("Connecting Wifi...");
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.println("Connecting to WiFi..");
      
  }
  Serial.println("IP address: ");
      
  Serial.println(WiFi.localIP());

  initCamera();

  timeClient.begin();
  timeClient.update();


  Serial.println(timeClient.getFormattedTime());

  ftp.OpenConnection();
}

void loop() {
  timeClient.update();
  takePhoto();
  delay(1000);
}

void initCamera() {
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG; 
  
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;//FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }  
  // Init Camera
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }  
}

void takePhoto() {

      
  camera_fb_t * fb = NULL;
  
  
  // Take Picture with Camera
  fb = esp_camera_fb_get();  
  if(!fb) {
    Serial.println("Camera capture failed");
    return;
  }

  /*
   * Upload to ftp server
   */
  

 /*ftp.ChangeWorkDir(ftp_path); */
  ftp.InitFile("Type I");

  String nombreArchivo = timeClient.getFormattedTime()+".jpg"; // AAAAMMDD_HHMMSS.jpg
  Serial.println("Subiendo "+nombreArchivo);
  int str_len = nombreArchivo.length() + 1; 
 
  char char_array[str_len];
  nombreArchivo.toCharArray(char_array, str_len);
  
  ftp.NewFile(char_array);
  
  ftp.WriteData( fb->buf, fb->len );
  Serial.println("test");
  ftp.CloseFile();
  
  /*
   * Free
   */
  esp_camera_fb_return(fb); 
}
Serial Monitor:
20:22:06.974 -> Connecting Wifi...
20:22:07.486 -> Connecting to WiFi..
20:22:07.486 -> IP address: 
20:22:07.486 -> 192.168.0.62
20:22:22.917 -> 03:28:33
20:22:22.917 -> Connecting to: 192.168.0.10
20:22:22.917 -> Command connected
20:22:22.952 -> Send USER
20:22:27.956 -> FTP error: Offline
20:22:27.956 -> Send PASSWORD
20:22:32.958 -> FTP error: Offline
20:22:32.958 -> Send SYST
20:22:37.980 -> FTP error: Offline
20:22:53.064 -> Send TYPE
20:22:53.064 -> FTP error: Offline
20:22:53.064 -> Subiendo 03:29:03.jpg
20:22:53.098 -> Send STOR
20:22:53.098 -> FTP error: Offline
20:22:53.098 -> Writing
20:22:53.098 -> FTP error: Offline
20:22:53.098 -> test
20:22:53.098 -> Close File
FTPserver log:
2021-01-14 20:22:22,576 server proftpd[20092] localhost (192.168.0.62[192.168.0.62]): FTP session opened.
2021-01-14 20:23:22,811 server proftpd[20092] localhost (192.168.0.62[192.168.0.62]): USER test: Login successful.

I don't know wehre the issue is. There is not much about on google.
Eventually you see something that i made wrong.

FTP Server:
ProFTP

FTP port hardcoded?

Hi there; Thanks for writing this guys, it is coming in really handy.

Question: Is there any reason that the FTP port is hardcoded to 21? What do you think about taking that as an additional variable (and maybe with a default of 21?)

A couple of FTP servers we're accessing use alternate ports (I suppose for "security" but...), I got around it by changing the hardcoded value (in ESP32_FTPClient.cpp at line 132). I am sure that will bite me somehow in the future, but it worked!

Just thinking I might not be the only guy with this need, thought I would ask.

M

SPIFFS

Hi
I try to execute de Spfiss code.
I find a problem in this line: ftp.WriteData(&file);
.Can you please help me?. Thank you very much

Arduino:1.8.10 (Windows 10), Tarjeta:"ESP32 Wrover Module, Huge APP (3MB No OTA/1MB SPIFFS), QIO, 80MHz, 115200, None"

C:\Users\rafa\Documents\Arduino\sketch_mar21a\sketch_mar21a.ino: In function 'void setup()':

sketch_mar21a:78:20: error: no matching function for call to 'ESP32_FTPClient::WriteData(fs::File*)'

ftp.WriteData(&file);

            ^

In file included from C:\Users\rafa\Documents\Arduino\sketch_mar21a\sketch_mar21a.ino:4:0:

C:\Users\rafa\Documents\Arduino\libraries\esp32_ftpclient\src/ESP32_FTPClient.h:42:8: note: candidate: void ESP32_FTPClient::WriteData(unsigned char*, int)

void WriteData (unsigned char * data, int dataLength);

^

C:\Users\rafa\Documents\Arduino\libraries\esp32_ftpclient\src/ESP32_FTPClient.h:42:8: note: candidate expects 2 arguments, 1 provided

Se encontraron varias bibliotecas para "WiFi.h"
Usado: C:\Users\rafa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
No usado: C:\Program
Se encontraron varias bibliotecas para "ESP32_FTPClient.h"
Usado: C:\Users\rafa\Documents\Arduino\libraries\esp32_ftpclient
Se encontraron varias bibliotecas para "FS.h"
Usado: C:\Users\rafa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS
Se encontraron varias bibliotecas para "SPI.h"
Usado: C:\Users\rafa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPI
Se encontraron varias bibliotecas para "SD_MMC.h"
Usado: C:\Users\rafa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD_MMC
Se encontraron varias bibliotecas para "SPIFFS.h"
Usado: C:\Users\rafa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPIFFS
exit status 1
no matching function for call to 'ESP32_FTPClient::WriteData(fs::File*)'

Este informe podría contener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.

Sending CSV files From SD card to FTP Server

My csv File which is present in SD card, is not send appropriately to the ftp File Server. The code is below

void Send_FTP_file(fs::FS& fs, const char* path, ESP32_FTPClient ftpClient) {
//Serial.printf("Reading file: %s\n", path);

String fullPath = "/";
fullPath.concat(path);
File file = SD.open(fullPath);
if(!file){
    Serial.print("Failed to open file for reading");
    return;
}

ftpClient.InitFile("Type I");
ftpClient.NewFile(path);
//ftpClient.WriteData( file, sizeof(file) );

while (file.available()) {
    // Create and fill a buffer
    unsigned char buf[1024];
    int readVal = file.read(buf, sizeof(buf));
    ftpClient.WriteData(buf,sizeof(buf));
}*
ftpClient.CloseFile();
file.close();

}

ESP32 send email

HI, have you solutions also for send email?
Have you example?
Thanks
Umberto

Upload image from SD-CARD

Hello and sorry for the inconvenience.
I encountered a problem when I try to copy a jpg image from the SD-CARD to the FTP area.
The image is copied correctly but is unreadable.
I attach the part of code that performs this operation.
I would be grateful if you could help me solve the problem.
Best regards.
UPLOAD.zip

FTP error : Offline

Hello, is any condition that make ftp show "FTP error : Offline" when uploading file? i had a problem with ftp.OpenConnection(); sometimes when try to uploading file. Thanks for your answer

FTP Offline

code:-
ESP32_FTPClient ftp1 (ftp_server_t,ftp_user_t,ftp_pass_t,3000,2);

void ftp_send(){
int chn;
if(FTP_enable){
if(ftp_enable1==1){
ftp1.OpenConnection();
if(ftp1.isConnected()){
Serial.println("FTP 1 : Connected");
ftp1.ChangeWorkDir(ftp_dir[0]);
for(chn=0;chn<sensors;chn++)
{
if(enchn[chn]!=0){
char fname[30];
char dem[30];
//String temp ="20230324_KVARtest1.csv";
sprintf(fname,"%04d%02d%02d_%s.csv",curdate.year+2000,curdate.mon,curdate.date,compid[chn].c_str());
//sprintf(fname,"%s",temp);
Send_FTP_file(SD, fname, ftp1); // 272,546
sprintf(dem,"File Send: %s",fname);
Serial.println(dem);
}
}
}else{
Serial.println("FTP 1 : DISCONNECTED");
}
ftp1.CloseConnection();

}

}

void Send_FTP_file(fs::FS& fs, const char* path, ESP32_FTPClient ftpClient) {
//Serial.printf("Reading file: %s\n", path);

String fullPath = "/";
fullPath.concat(path);
Serial.print("File Path:");
Serial.print(path);
File file = SD.open(fullPath);
if(!file){
    Serial.print("Failed to open file for reading");
    return;
}

ftpClient.InitFile("Type I");
ftpClient.NewFile(path);
char sz = file.size();
int fileSize = file.size();
Serial.print("File Size:");
Serial.print(fileSize);   
unsigned char * downloaded_file = (unsigned char *) malloc(fileSize);    
size_t bytesRead = file.read(downloaded_file, fileSize); // read the file contents into the array   
//const char* myString = reinterpret_cast<const char*>(downloaded_file);  // for converting unsigned char to const char*
ftpClient.WriteData(downloaded_file, fileSize);   
free(downloaded_file);
ftpClient.CloseFile();
file.close();

}

Error:
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
Send USER
Send PASSWORD
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected
FTP error: Offline
Connecting to: 13.126.134.217
Command connected....

It remains in the condition unitl FTP connected, Can u impalement no of tries in the FTPAnswer routine. To skip if tit exceeds no of tries . So that it can again try to reconnect when the function of send is called. Or is there any other way to tackle this issue

Create folder if it doesn't exist.

Hi,

I am trying to check if a folder exists and if not create it.
The folder structure is "/images/[imageset]/monochrome", "/images/[imageset]/color". As in /images/1/monochrome, /images/2/monochrome, ...

When uploading initially via

   String ftpprobestring = "/images/img" + String(counter) ;
   String ftpprobestring1 = ftpprobestring + "/col";
   String ftpprobestring2 = ftpprobestring + "/bw";
   ftp.OpenConnection();
   ftp.InitFile("TYPE A");
  
  ftp.MakeDir(ftpprobestring.c_str());
   ftp.MakeDir(ftpprobestring1.c_str());
   ftp.MakeDir(ftpprobestring2.c_str());
   ftp.CloseConnection();

every the program works like expected.
But if I want to create a folder that already exists I get a "550" for each attempt to create a folder - even if the following folders do not exist. For example the folder /1/ exists but the folders /monocrome/ and /color/ do not exist - I still get 3 answers "550".

I tried to create a list and check if one of the strings in said list contains the respective expressions - no success.

Is there a way to check if a folder exists and then create it?
Or use the server message like ftp.changeworkdir; if (server message == 550 ) makedir?

Cheers

If wifi connection drops it hangs cpu

If ftp.OpenConnection(); is called when the wifi connection had dropped the process blocks/hangs the cpu.

In my case I had it updating every 5 seconds and then I rebooted my router. The serial debug shows:

Connecting to: (ftp address)
Command connected

Then it halts.

Upload image from SD-CARD

"Try to open the file you believe you uploaded correctly with a text editor, you will find the problem there, ex."

Sorry but I don't understand what you mean.
Where am I wrong in transferring the image?
What is the correct way to transfer images from SD-CARD to FTP?
When you developed the very functional library, you will have foreseen this option. I would therefore ask you to explain it to me too so that I can use it. If the option is not provided, then just know and I will adapt to find a different solution.

Thank you for the time you dedicated to the problem, I think it will help everyone to grow in their knowledge of the potential of the library.

And in any case, it would be kind of you to avoid closing the conversation before having new feedback.

FTP error: offline

I read all those closed issue about offline, but I could not solve my problem yet. my code is like this

/******************************************************************************

ESP32-CAM remote image access via FTP. Take pictures with ESP32 and upload it via FTP making it accessible for the outisde network. 
Leonardo Bispo
July - 2019
https://github.com/ldab/ESP32_FTPClient

Distributed as-is; no warranty is given.

******************************************************************************/
#include "Arduino.h"
#include <WiFi.h>
#include <WiFiClient.h> 
#include <ESP32_FTPClient.h>
#include "octocat.h"

#define WIFI_SSID "IMTeam"
#define WIFI_PASS "IMTeamgogogo"

char ftp_server[] = "47.110.41.91";
char ftp_user[]   = "system";
char ftp_pass[]   = "OTA&mqtt1234.";

// you can pass a FTP timeout and debbug mode on the last 2 arguments
ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);

void setup()
{
  Serial.begin( 115200 );

  WiFi.begin( WIFI_SSID, WIFI_PASS );
  
  Serial.println("Connecting Wifi...");
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println("");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  ftp.OpenConnection();

  // Get directory content
  // ftp.InitFile("Type A");
  // String list[128];
  // ftp.ChangeWorkDir("/work/ftp/uploadFile");
  // ftp.ContentList("", list);
  // Serial.println("\nDirectory info: ");
  // for(int i = 0; i < sizeof(list); i++)
  // {
  //   if(list[i].length() > 0)
  //     Serial.println(list[i]);
  //   else
  //     break;
  // }

  // // Make a new directory
  // ftp.InitFile("Type A");
  // ftp.MakeDir("my_new_dir");

  // //Create the new file and send the image
  // ftp.ChangeWorkDir("my_new_dir");
  ftp.InitFile("Type I");
  ftp.ChangeWorkDir("/work/ftp/uploadFile/");
  ftp.NewFile("octocat.jpg");
  ftp.WriteData( octocat_pic, sizeof(octocat_pic) );
  ftp.CloseFile();

  // Create the file new and write a string into it
  ftp.InitFile("Type A");
  ftp.ChangeWorkDir("/work/ftp/uploadFile/");
  ftp.NewFile("hello_world.txt");
  ftp.Write("Hello World");
  ftp.CloseFile();

  ftp.CloseConnection();
}

void loop()
{

}

and I got results like this :

IP address: 192.168.10.108
Connecting to: 47.110.41.91
Command connected
Send USER
Send PASSWORD
Send SYST
Send TYPE
Type I
Send PASV
Data port: 34489
Send CWD
Send STOR
FTP error: Offline
Writing
FTP error: Offline
Close File
Send TYPE
FTP error: Offline
Send CWD
FTP error: Offline
Send STOR
FTP error: Offline
Write File
FTP error: Offline
Close File
Connection closed

I can see those files that I uploaded just appear in my ftp server through FileZilla, but all of them are 0 byte size.
It seems that I can creat a new file but I cannot write data to those files created by myself.
So what is my peoblem with my ftp server or client ?
Thanks so much !

ftp.write

it does not write files larger than 63K
and the semi-finished file is released
Are there limits defined for this part FTP.write

How do I properly close the connection using this library?

After the upload I issue these commands;

  ftp.CloseFile();
  ftp.CloseConnection();

However eventually my server says "FTP error: 530 Sorry, the maximum number of connections (10) for your host are already connected.".
Is it possible to add a "QUIT" or "BYE" using this library to properly log off?

IP address of the response for PASV command should be referred

IP address of the response for PASV command should be referred like the below, because some of ftp servers set other IP addresses than itself.

void ESP32_FTPClient::InitFile(const char* type){
FTPdbgn("Send TYPE");
if(!isConnected()) return;
FTPdbgn(type);
client.println(F(type));
GetFTPAnswer();
` FTPdbgn("Send PASV");` ` client.println(F("PASV"));` ` GetFTPAnswer();`
char *tStr = strtok(outBuf, "(,");
int array_pasv[6];
for ( int i = 0; i < 6; i++) {
tStr = strtok(NULL, "(,");
if (tStr == NULL) {
FTPdbgn(F("Bad PASV Answer"));
CloseConnection();
return;
}
array_pasv[i] = atoi(tStr);
}
unsigned int hiPort, loPort;
hiPort = array_pasv[4] << 8;
loPort = array_pasv[5] & 255;

//Qamada added
IPAddress pasvServer(array_pasv[0],array_pasv[1],array_pasv[2],array_pasv[3]);
//Qamada added

FTPdbg(F("Data port: "));
hiPort = hiPort | loPort;
FTPdbgn(hiPort);
//Qamada modified
//if (dclient.connect(serverAdress, hiPort, timeout)) {
if (dclient.connect(pasvServer, hiPort, timeout)) {
FTPdbgn(F("Data connection established"));
}
}

I test this code on ftp server of http://web.fc2.com/en/ in order to evaluate this modification.

FTP PORT

Hi, be patient but I can't solve my problem.
I checked with my provider the port enabled for managing the FTP area.
Once I had carried out this check I tried to make this connection by inserting the indicated FTP port into the call.
I defined the FTP_POR variable as short and executed the call:
ESP32_FTPClient ftp (FTP_SER,FTP_POR,FTP_USR,FTP_PWD, 5000, 2);

With the port assigned by my FTP provider, 2201, I cannot connect.
With port 21, I can connect.
If I follow the connection with FTP Filezilla, using port 2201 I can connect.
Can you give me some advice?
Thanks and good job

FTP PORT

Yes, I have actually already done these tests and Filezilla actually works correctly.
I detect the problem when I try to change the value of the FTP port (from 21 to 2201)
In this regard, I was wondering how the library identifies the type of call to the FTP connection between:
ESP32_FTPClient ftp (FTP_SER,FTP_POR,FTP_USR,FTP_PWD, 5000, 2);
And
ESP32_FTPClient ftp (FTP_SER,FTP_USR,FTP_PWD, 5000, 2);

Thanks and good job

Issue when overwritting a file

Hi,

Thanks for the work on this library.

I'm trying to use it to overwrite the same file again and again to a FTP server in the same stream (that is without closing the connection because it has to be very fast and closing the file, reopening it and closing and reopening the connection add a huge delay).

However the file on my server is not properly overwritten it just keeps on growing instead (the size of the file gets bigger and bigger)

Any thought if this expected or if there is something that can be done to overwrite the file without having to reopen a new data connection every time ?

Thanks.

hanging when ftp password is incorrect

With the current code from this repository if a password is wrong it has a long pause when it returns the dataport number but does continue and when it gets to the Closefile the last thing it tries to run is GetFTPAnswer(); but does not return from that.

void ESP32_FTPClient::CloseFile () { Serial.println(F("Close File")); dclient.stop(); Serial.println("still running1"); GetFTPAnswer(); Serial.println("still running2"); }

I do not get a serial output afterwards and it never returns back to the main loop.

Also ideally if the pasv is bad then it should exit instead of trying to connect and give the long pause for the data connection.

Maybe Initfile can return a response whether it was successfull so the user app can then determine if it needs to continue?

Plus I am not sure why it responds with data connection established when the password fails?

Bad PASV Answer

I use the example, filled with correct adresses and passwords, changed the ChangeWorkDir from "/public_html/zyro/gallery_gen/" to "/Dokumente" (what is already there) and replaced the 'ContentList' with the 'ContentListWithListCommand'..
I don't know.. it just doesn't work. I tried for hours..
here is the code (without Wifi and ftp data)

ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);

void setup()
{
  Serial.begin( 115200 );

  WiFi.begin( WIFI_SSID, WIFI_PASS );
  
  Serial.println("Connecting Wifi...");
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println("");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  ftp.OpenConnection();

  // Get directory content
  ftp.InitFile("Type A");
  String list[128];
  ftp.ChangeWorkDir("/Dokumente");
//  ftp.ContentList("", list);
  ftp.ContentListWithListCommand("", list);

  Serial.println("\nDirectory info: ");
  for(int i = 0; i < sizeof(list); i++)
  {
    if(list[i].length() > 0)
      Serial.println(list[i]);
    else
      break;
  }

  // Make a new directory
  ftp.InitFile("Type A");
  ftp.MakeDir("my_new_dir");

  // Create the new file and send the image
  ftp.ChangeWorkDir("my_new_dir");
  ftp.InitFile("Type I");
  ftp.NewFile("octocat.jpg");
  ftp.WriteData( octocat_pic, sizeof(octocat_pic) );
  ftp.CloseFile();

  // Create the file new and write a string into it
  ftp.InitFile("Type A");
  ftp.NewFile("hello_world.txt");
  ftp.Write("Hello World");
  ftp.CloseFile();

  ftp.CloseConnection();
}
void loop(){}

then i get this Serial Output:

Connecting Wifi...
.....
IP address: 192.168.0.119
Connecting to: 192.168.0.1
Command connected
Send USER
Send PASSWORD
Send SYST
Send TYPE
Type A
Send PASV
Data port: 43174
Data connection established
Send CWD
Send LIST
Result start
Result: 150 Opening ASCII mode data connection for '/bin/ls -lgA'.
Result end

Directory info: 
FRITZ-NAS.txt
Produkthandbuch.html
Send TYPE
Type A
Send PASV
Bad PASV Answer
Connection closed
Send MKD
FTP error: Offline
Send CWD
FTP error: Offline
Send TYPE
FTP error: Offline
Send STOR
FTP error: Offline
Writing
FTP error: Offline
Close File
Send TYPE
FTP error: Offline
Send STOR
FTP error: Offline
Write File
FTP error: Offline
Close File
Connection closed

I don't know why the second PASV is bad. I am a bit desperate, there is no alternate Arduino-FTP but this one does not work at all for me (I tried 2 different boards, but have only this one server on my Fritz.Box Router).. Should I try something else? SSH?

Unknown Commands

Hi,

I am having issues with error code 500 and the ftp server not understanding any commands. Does the server need any special programs installed to interpret this code? I have a pi 3b+ running a simple ftp server. The code I am running is the example upload code with just the wifi and server info changed. I cant get past the unknown commands to do things like change the directory. I should note that the connection to the server looks good its just when I start to issue commands for the server.

I understand that this may not be a bug but I would love any help you all are willing to give non the less. Thank you for your time.

FTP_Code_Home.txt

Esp32 resets wen data is sennding

The log of the file is given below, the reset happens frequently . I have cross checked the user name, passwords host served details :
'''
Send TYPE
Type I
Send PASV
Data port: 65218
Data connection established
Send STOR
File Size:414761Writing
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

Core 0 register dump:
PC : 0x400f42d7 PS : 0x00060730 A0 : 0x800f4338 A1 : 0x3ffdf050
A2 : 0x3ffdf108 A3 : 0x3ffdf1b8 A4 : 0x00000000 A5 : 0x00065429
A6 : 0x00000000 A7 : 0x000000ef A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000001 A11 : 0x00000001 A12 : 0x00065429 A13 : 0x3ffb6954
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x0000000f EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4008ac25 LEND : 0x4008ac35 LCOUNT : 0xfffffffe


Backtrace: 0x400f42d4:0x3ffdf050 0x400f4335:0x3ffdf070 0x400e91cf:0x3ffdf090 0x400e96f2:0x3ffdf0e0




ELF file SHA256: 153cbdbb158e7ded

E (16979) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0
Rebooting...
ÓRöîfgRâ
'''

Sending File format to ftp

I have been trying to read the sd card file and then write it to the ftp server , which causes 2 major issues

  1. The file is large which causes it to use all the string allocated memory, and then only been able to send only limited data. Is there any way to Send the File to FTP using File format?
  2. File needs to written byte by byte , any faster way to do it?

Unexpected FTP error:offline

Hi,,
In a little project I want to send a photo form an ESP32cam via FTP to a webserver. The server is my webpagehoster, so not a Filezilla Server within my own LAN domain.
To check out whether the FTP transfer from my ESP to the server works I used your upload code example.

Findings:

  1. Accessing the FTP server works fine, Username and Password are accepted.

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
Connecting Wifi...
.....
IP address: 192.168.2.173
Connecting to: myserver.myWebhoster.com (I anonymized the server name)
Command connected
Send USER
Send PASSWORD
Send SYST
Send TYPE
Type A
Send PASV
Data port: 53624
Data connection established

  1. Changing into a (beforehand with Filezilla defined) working Directory sees to work fine as well, even though there are not only the files listed, but lots of additional information. However, the (beforehand with filezilla uploaded) file Termini.jpg was found.

Serial Monitor output:
Send CWD
Send MLSD
Result start
Result: 150 Opening ASCII mode data connection for MLSD
Result end
Directory info:
modify=20210417101532;perm=flcdmpe;type=cdir;unique=FD00U28833ED;UNIX.group=1004;UNIX.groupname=psacln;UNIX.mode=0755;UNIX.owner=10047;UNIX.ownername=web553f4; .
modify=20210417101137;perm=flcdmpe;type=pdir;unique=FD00U2689C0E;UNIX.group=1004;UNIX.groupname=psacln;UNIX.mode=0755;UNIX.owner=10047;UNIX.ownername=web553f4; ..
modify=20210417101533;perm=adfrw;size=23993;type=file;unique=FD00U287C1A8;UNIX.group=1004;UNIX.groupname=psacln;UNIX.mode=0644;UNIX.owner=xxxx;UNIX.ownername=myUsername; Termini.jpg`

  1. Next command in the code are:
    // Make a new directory
    ftp.InitFile("Type A");
    ftp.MakeDir("my_new_dir");

The Serial Monitor shows from now on an Offline Error

Send TYPE
Type A
FTP error: Offline
Send PASV
FTP error: Offline
Bad PASV Answer
Connection closed
Send MKD
FTP error: Offline
Send CWD
FTP error: Offline
Send TYPE
FTP error: Offline
Send STOR
FTP error: Offline
Writing
FTP error: Offline
Close File
Send TYPE
FTP error: Offline
Send STOR
FTP error: Offline
Write File
FTP error: Offline
Close File
Connection closed

Any idea why the Offline Error occurs?
Anything I can check?

Thanks!

FTP PORT

If you want I can close the matter here and not bother you anymore.
However, the problem remains open because, using your wonderful library, everything works until I try to change the FTP access port. This isn't about the Arduino or the code used because I use the calls that your library provides.
So assuming that:

  1. The provider provided me with access port 2201
    2)Filezilla correctly accesses the selected FTP area through this port
  2. The call of your library:
    ESP32_FTPClient ftp (FTP_SER,FTP_POR,FTP_USR,FTP_PWD, 5000, 2);
    works only if FTP_POR = 21.
    The code used here has nothing to do with it.
    If you can kindly send me a concrete example of code that I can understand, I would be grateful.
    If you need to intervene on ESP32_FTPClient.cpp or ESP32_FTPClient.h tell me how to do it.
    My impression is that the call is not made where the FTP port is specified.
    If you want to help me I would be infinitely grateful otherwise, as they say where I come from, thanks anyway and have a good life.

Verification for FTP functions/commands

Hello.
First of all I want to state that this is not an issue, I just didn't know where else to post that question.
Also, I want to thank you for this library, it helped me in a state of emergency :P

Is there any way to verify that a certain action (for example: ftp.Write(...) ) was done successfully?
There is already a function called ftp.isConnected() that returns a boolean but what if I want to do multiple actions during a connection and some of them just don't happen from the server's side.

I understand that the function GetFTPAnswer is used for debugging/verification but I cant implement a proper condition since every other functions returns void.

Thank you in advance.

hanging when connection is dropped

I don't know if this was on your radar but when the connection is dropped I am getting a hang when it calls

if (dclient.connect(serverAdress, hiPort)) {

Maybe this doesn't have a timeout? Or is the data corrupt. The serial output looks like:

Send PASV
Bad PASV Answer
Data port: 4228875273
(then hangs)

That port number is very high. Is that because the response got corrupted and maybe that is hanging the connect because the port number is out of bounds or something? Maybe if the port number is not a valid range it needs to exit.

FTP error: 500 'MLSD': command not understood.

I tried to use ESP32_FTPClient to get ESP32 to send measurements via FileApend to a local file location via WiFi.
But it didn't work.. several reasons, this is the first:
Serial Monitor is repeating:FTP error: 500 'MLSD': command not understood.

Well, I think I found the reason, but I think that maybe others are also looking for this bug and then maybe a recommendation from the developer would be quite good.
So far my experience:
MLSD command is not 'original' FTP, so some devices probably don't offer it (my quite recent and popular Fritz!Box3490 for example). Without MLSD nothing works in the given example... what to do?
The error occurs when calling

ftp.ContentList("", list);

and I found in the sourcecode that there is a workaround: instead of "ContentList" take "ContentListWithListCommand", so like this:

ftp.ContentListWithListCommand("", list);

If I am right, it would be great if this should be mentioned! If I am not right please give the correct anwer!

Wifi by smartphone HotSpot

Hello and sorry if I bother you.
I used this splendid library for a project related to the ESP32CAM board.
The purpose is to read some parameters, via Wifi, from Firebase to parameterize the photo shot, take the shot and save it in an FTP area.
Working with a home WiFi, everything works perfectly.
Using a phone's HotSpot, the firebase connection part works while the application cannot handle the FTP connection.
I use the connection where the port is automatically set to 21.
Do you have any suggestions?
Best regards

Parametric management of FTP parameters

Hello and congratulations for the good work done.
I tried the library and everything works great.
Now however, I would like to make the access parameters to the FTP area parametric.
I planned to read these parameters from SD-CARD and assign them to the variables:

char ftp_server[] = "";
char ftp_user[] = "";
char ftp_pass[] = "";

for example :

String FTP_SER;
String FTP_USR;
String FTP_PWD;

these variables are read from SD-CARD.

Then I try to do:
char ftp_server[] = FTP_SER;
char ftp_user[] = FTP_USR;
char ftp_pass[] = FTP_PWD;

but I can't get it to work no matter what I try.
It's true that I'm not very good with the Arduino language but it seems strange to me not to be able to manage something apparently so simple.

Would you be so kind as to give me a hand.
Thank you for any collaboration.

myPhoto.png or myphoto.png in example download_file.ino?

Hi ldab. I have executed your example download_file.ino using my 000webhost.com account.
On the Serial Monitor (output not shown here) I saw that myPhoto.png did not exist.
Reading your .ino file I made out at that I first had to create a picturefile with that name and had to upload that file into the working directory (public_html/xxx). After I had done so the Serial Monitor output (verbose=2 and Serial.println(outBuf) in the ESP32-FTPClient.cpp at line 87) was -> see List-1.txt.
List-1.txt

The result of this is that only helloworld.txt is written to the working directory /xxx
and the Filesize (of myPhoto.png) is: 0. And MyNewDir is not created.
Then I renamed myPhoto.png in your download_file.ino into myphoto.png (all lowercase letters).
The output of the Serial Monitor -> SeeList-2.txt.
List-2.txt

Finally I also renamed myPhoto.png in my working directory /xxx into myphoto.png (all lowercase letters).
The Serial Monitor output is in List-3.txt.
List-3.txt

I observe at line 77 of your .ino file list[i].toLowerCase(), but that is only the way how the files are shown in the list? Does it have anything to do with that?
Maybe I have done something wrong.
In general, I think it would be nice to add the Serial Monitor output to the examples as a reference comparison.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.