ESP32 login to FTP server using GPRS does not work.

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

ESP32 login to FTP server using GPRS does not work.

Postby Pcborges » Wed Apr 29, 2020 11:30 pm

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.

Code: Select all


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:

Code: Select all

byte doFTP(){
  const char* ftpServer = "ftp.myserver.com";

  if (client.connect(ftpServer,21)) {    -------------- - connection works OK.
    Serial.println(F("Command connected"));  <------Check printed CONNECTION 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;
}
Also tested against another FTP server: speedtest.tele2.net (user anonymous, pass anonymous)
* uploaded files are immediately deleted by the system as it is for test only.

The same code on the post above was used (only credentials were changed) and my impression is that if failed at precisely the same place: USER anonymous

Using FileZilla I can transfer a file (that is immediately deleted) but the transfer runs OK.

The connection dialog registered at the serial console is as below:

Code: Select all

Command connected
Login process...
220 (vsFTPd 3.0.3)
221 Goodbye.
Command disconnected
FTP FAIL
Server disconnected
GPRS disconnected
Any help welcome
Paulo

Who is online

Users browsing this forum: No registered users and 64 guests