Hi, I am trying to use preferences to store authentication credentials for an FTP server.
When credentials are hard coded it works but when credentials come from storage it does not.
Authentication fails.
The format of the hard coded credentials that work are commented out.
All variables are stored as Strings in the preferences flash memory and converted as necessary.
It works everywhere, with WiFi and SMTP but fails with this ftp.
The library used is:
// FTP Client Lib
#include "ESP32_FTPClient.h"
The portion of the code with the problem is as follows:
void FTP_upload(String pic_name){
//FTP parameters
preferences.begin("AppParms", false);
String Server = preferences.getString("ftpServer", ""); //toCharArray(ftpServer,sizeof(ftpServer));
String User = preferences.getString("ftpUser", ""); //toCharArray(ftpUser,sizeof(ftpUser));
String Pass = preferences.getString("ftpPass", ""); //toCharArray(ftpPass,sizeof(ftpPass));
preferences.end();
Server.trim();
User.trim();
Pass.trim();
Serial.print(" Strings: #");
Serial.print(Server);
Serial.print("#");
Serial.print(User);
Serial.print("#");
Serial.print(Pass);
Serial.println("#");
char ftp_server[Server.length()+1];
char ftp_user[User.length()+1];
char ftp_pass[Pass.length()+1];
Server.toCharArray(ftp_server,Server.length()+1);
User.toCharArray(ftp_user,User.length()+1);
Pass.toCharArray(ftp_pass,Pass.length()+1);
Serial.print(" FTP Parms: #");
Serial.print(ftp_server);
Serial.print("#");
Serial.print(ftp_user);
Serial.print("#");
Serial.print(ftp_pass);
Serial.println("#");
//ESP32_FTPClient ftp("host.ftpserver.com", "ftpuser", "ftppass"); //WORKS OK
ESP32_FTPClient ftp(ftp_server, ftp_user, ftp_pass); //Compile but fails
Serial.println("Transferindo imagem para FTP Server...");
ftp.OpenConnection();
//Create a file and write the image data to it;
ftp.InitFile("Type I");
//ftp.ChangeWorkDir("/public_html/zyro/gallery_gen/"); // change it to reflect your directory
const char *f_name = pic_name.c_str();
ftp.NewFile( f_name );
ftp.WriteData(fb->buf, fb->len);
ftp.CloseFile();
// Breath, withouth delay URL failed to update.
Serial.println("Concluido...");
delay(100);
}
Assistance welcome.
Thanks
Paulo