Preferences with FTP Client ESP32_FTPClient.h fails

Pcborges
Posts: 26
Joined: Thu Aug 09, 2018 9:56 pm

Preferences with FTP Client ESP32_FTPClient.h fails

Postby Pcborges » Sat Oct 12, 2019 1:27 pm

I need to initialize FTP connection with credentials stored on Preferences.

If I hard code like:
//ESP32_FTPClient ftp("host.ftpserver.com", "ftpuser", "ftppass"); //WORKS OK

Code: Select all

preferences.begin("AppParms", true);
String myserver = preferences.getString("ftpServer",""); 
String myuser = preferences.getString("ftpUser",""); 
String mypass = preferences.getString("ftpPass",""); 
preferences.end();

char* ftp_server[32]; 
char* ftp_user[32]; 
char* ftp_pass[16]; 
strncpy(myserver.c_str(), ftp_server, 32); <----- 
strncpy(myuser.c_str(), ftp_user, 32); 
strncpy(mypass.c_str(), ftp_pass, 16);
I am getting invalid conversion from 'const char*' to 'char*' [-fpermissive]

Char is required to initialize:
ESP32_FTPClient ftp(ftp_server, ftp_user, ftp_pass);

That refuses to accept:
ESP32_FTPClient ftp(myserver.c_str(), myuser.c_str(), mypass.c_str());

My system=ESP32 and lib in use:
// FTP Client Lib
include "ESP32_FTPClient.h"

Code: Select all

  char* ftp_server[32];
  char* ftp_user[32];
  char* ftp_pass[16];
  myserver.toCharArray(ftp_server, sizeof(ftp_server));
  myuser.toCharArray(ftp_user, sizeof(ftp_user));
  mypass.toCharArray(ftp_pass, sizeof(ftp_pass));
Also fails with:
no matching function for call to 'String::toCharArray(char* [32], unsigned int)'

******************************************************************************************
Problem solved!

Code: Select all

  char ftp_server[32];
  char ftp_user[32];
  char ftp_pass[16];

  //FTP parameters
  preferences.begin("AppParms", true);
  strncpy(ftp_server,preferences.getString("ftpServer").c_str(),  sizeof(ftp_server));
  strncpy(ftp_user,preferences.getString("ftpUser").c_str(),      sizeof(ftp_user));
  strncpy(ftp_pass,preferences.getString("ftpPass").c_str(),      sizeof(ftp_pass));
  preferences.end();
 
  ESP32_FTPClient ftp(ftp_server, ftp_user, ftp_pass);  
Thanks
Last edited by Pcborges on Sat Oct 12, 2019 5:30 pm, edited 1 time in total.

chegewara
Posts: 815
Joined: Wed Jun 14, 2017 9:00 pm

Re: Preferences with FTP Client ESP32_FTPClient.h fails

Postby chegewara » Sat Oct 12, 2019 5:26 pm

1st issue is that you are instantiating array of 32/16 pointers to char:

Code: Select all

char* ftp_server[32]; 
char* ftp_user[32]; 
char* ftp_pass[16]; 
but most likely you want array of 32/16 char:

Code: Select all

char ftp_server[32]; 
char ftp_user[32]; 
char ftp_pass[16]; 
2nd issue:
if you have error like this:
invalid conversion from 'const char*' to 'char*' [-fpermissive]
you can always cast to:

Code: Select all

 (char*)variable

Who is online

Users browsing this forum: No registered users and 7 guests