Best way to transfer large data from Photon

@peekay123 Clarification question, if you have time. Is Passive FTP going to be able to return the contents of my directory with a command like LIST?

Currently i’m just trying to get the contents to print out in the serial monitor (just to make sure i’m sending the command correctly) then i’ll try putting it in a local array of strings for downloading with something like client.write(etc)…client.read(etc). The server just returns 150: Connection accepted, additionally I have tried dir and referencing the directory path.

byte directoryPrint()
{

//  if (client.connect(server,21)) { // port number is 21 for driveHQ
    if (client.connect(server, 21)){
    Serial.println("Command connected");
  }
  else {
    Serial.println("Command connection failed");
    return 0;
  }


  // For remote FTP server replace particle with username and photon with password, ftp.drivehq.com/drivehqshare/clabadmin/dev1-2
  // unsure about the format for the rest but PASV is likely passive TCP
  if(!eRcv()) return 0;
  client.println("USER ...");
  if(!eRcv()) return 0;
  client.println("PASS ...");
  if(!eRcv()) return 0;
  client.println("CWD /drivehqshare/...");
  if(!eRcv()) return 0;
  client.println("SYST");
  if(!eRcv()) return 0;
  client.println("Type ascii");
  if(!eRcv()) return 0;
  client.println("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("Bad PASV Answer");
    }
  }

  unsigned int hiPort,loPort;

  hiPort = array_pasv[4] << 8;
  loPort = array_pasv[5] & 255;

  Serial.print("Data port: ");
  hiPort = hiPort | loPort;
  Serial.println(hiPort);

  if (dclient.connect(server,hiPort)) {
    Serial.println("Data connected");
  }
  else {
    Serial.println("Data connection failed");
    client.stop();
    return 0;
  }

  Serial.println("Testing List Command");

  client.println("LIST");
  if(!eRcv()) return 0;


  Serial.println("List Command Has been Issued");

  if(!eRcv())
  {
    dclient.stop();
    return 0;
  }

  dclient.stop();
  Serial.println("Data disconnected");

  if(!eRcv()) return 0;
  client.println("QUIT");
  if(!eRcv()) return 0;
  client.stop();
  Serial.println("Command disconnected");

  return 1;
}

@peekay123 Nevermind! You can ignore my previous post, I found out what I was doing wrong (after many frustrating days!). I was expecting something to return in serial monitor after sending

client.println("NLST");

or

client.println("LIST");

but the only thing that was returning was connection accepted. So I tried reading the client buffer and serial printing, it just came back with -1 or basically null. Then I finally cued in that I was reading the wrong buffer for data, I should have been reading the dclient buffer! So basically my edit to the code is below (which should be modified) to return file directory names in 8.3 format.

Serial.println("Testing NLST Command");
byte testBuffer[12];

client.println("NLST");
if(!eRcv()) return 0;

dclient.read(testBuffer, 12);
String val = String((char*)testBuffer);
Serial.println(val);
Serial.println("List Command Has been Issued");

1 Like