Hi, I am trying to transfer a small image (5k) to an FTP server (http would also do) but so far no success.
The line: client.connect(ftpServer,21) works and the FTP server returns its welcome text but nothing else works.
I can connect with the same credentials using telnet (using Putty).
In my case the response from the FTP Server is as below and it testifies that the GPRS connection is active and working.
Command connected ----------SEE ON CODE
Login process...
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 4 of 150 allowed.
220-Local time is now 13:29. Server port: 21.
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.
Notice that except for the connection request, nothing else seems to be received by the FTP server.
The ESP32 sketch is too big but the relevant segment is listed below:
byte doFTP(){
const char* ftpServer = "ftp.myserver.com";
if (client.connect(ftpServer,21)) { -------------- - connection works OK.
Serial.println(F("Command connected")); <------Check printed CONECTION above
} else {
Serial.println(F("Command connection failed"));
return 0;
}
Serial.println("Login process...");
// send login name and password
if(!eRcv()) return 0;
client.println(F("USER myUserName@ftp.myservercom"));
if(!eRcv()) return 0;
client.println(F("PASS myPass"));
if(!eRcv()) return 0;
client.println(F("SYST"));
if(!eRcv()) return 0;
client.println(F("Type I"));
if(!eRcv()) return 0;
client.println(F("PASV"));
if(!eRcv()) return 0;
char *tStr = strtok(outBuf,"(,");
int array_pasv[6];
for ( int i = 0; i < 6; i++) {
tStr = strtok(NULL,"(,");
array_pasv[i] = atoi(tStr);
if(tStr == NULL){
Serial.println(F("Bad PASV Answer"));
}
}
// TinyGSM Client for Internet connection
TinyGsmClient dclient(modem);
unsigned int hiPort,loPort;
hiPort = array_pasv[4] << 8;
loPort = array_pasv[5] & 255;
Serial.print(F("Data port: "));
hiPort = hiPort | loPort;
Serial.println(hiPort);
if (dclient.connect(ftpServer,hiPort)) {
Serial.println(F("Data connected"));
}else{
Serial.println(F("Data connection failed"));
client.stop();
return 0;
}
// setup to send file file fileName
client.print(F("STOR "));
client.println("myNewPic.jpg");
if(!eRcv()){
dclient.stop();
return 0;
}
// send file contents
//dclient.write(clientBuf,clientCount);
Serial.println(F("Starting FTP transfer..."));
dclient.write((uint8_t*)tempImageBuffer,ImgMetaData.imSize);
dclient.stop();
Serial.println(F("Data disconnected"));
if(!eRcv()) return 0;
client.println(F("QUIT"));
if(!eRcv()) return 0;
client.stop();
Serial.println(F("Command disconnected"));
return 1;
}
Assistance welcome
Paulo