FTP Error 425 over wifi

So ive been working on getting a file transferred from an sd card to an ftp server, and i having some issues. As stated above im getting a 425 error on the the FTP server side. I have opened the ports up on my router for the data connection. But still no luck

hardware:
uC Teensy 3.2
Wifi ATWINC1500 from adafruit
SD card + Module

I am aware the the Arduino wifi shield is not capable of handling two sockets at a time.
Here is the link for the data sheet for the chip im using ATWINC1500 Datasheet

so if anyone has come across this issue or know a work around/ fix and could pass it on to me that would be greatly appreciated

#include <FreeStack.h>
#include <MinimumSerial.h>
#include <SdFat.h>
#include <SdFatConfig.h>
#include <SdFatUtil.h>
#include <SystemInclude.h>
#include <SPI.h>
#include <WiFi101.h>
#define FTPWRITE

SdFat SD;
SdFile file;
char ssid[] = "Run Faster Forest";     //  your network SSID (name)
char pass[] = "********";  // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

const uint8_t SD_chipSelect = 9;

// change to your server
IPAddress server( 192, 168, 1, 127 );

WiFiClient client;
WiFiClient dclient;

char outBuf[128];
char outCount;

// change fileName to your file (8.3 format!)
char fileName[13] = "Data_25.txt";

void setup()
{
  WiFi.setPins(10,6,2);
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  //Initialize SD card
 if (!SD.begin(SD_chipSelect, SPI_HALF_SPEED)) {
    SD.initErrorHalt();
  }
  
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
printWifiData()
    // wait 10 seconds for connection:
    delay(5000);
  }

delay(5000);
  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");

  //digitalWrite(10,HIGH);
  delay(2000);

  Serial.println(F("Ready. Press f or r"));
  
}

void loop()
{
  
  byte inChar;

  inChar = Serial.read();

  if(inChar == 'f')
  {
    if(doFTP()) Serial.println(F("FTP OK"));
    else Serial.println(F("FTP FAIL"));
  }

  if(inChar == 'r')
  {
    readSD();    
  }

}

File fh;

byte doFTP(){
#ifdef FTPWRITE
  fh = SD.open(fileName,FILE_READ);
#else
  SD.remove(fileName);
  fh = SD.open(fileName,FILE_WRITE);
#endif

  if(!fh)
  {
    Serial.println(F("SD open fail"));
    return 0;    
  }

#ifndef FTPWRITE  
  if(!fh.seek(0))
  {
    Serial.println(F("Rewind fail"));
    fh.close();
    return 0;    
  }
#endif

  Serial.println(F("SD opened"));

  if (client.connect(server,22)) {
    Serial.println(F("Command connected"));
  } 
  else {
    fh.close();
    Serial.println(F("Command connection failed"));
    return 0;
  }

  if(!eRcv()) return 0;

  client.println(F("USER Test"));
  if(!eRcv()) return 0;
  client.println(F("PASS 1988"));
  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"));
    }
  }
//  unsigned int hiPort,loPort;
//
//  hiPort = array_pasv[6] << 5000;
//  loPort = array_pasv[6] & 0;
//
//  Serial.print(F("Data port: "));
//  hiPort = hiPort | loPort;
//  Serial.println(hiPort);
//
//  if (dclient.connect(server,hiPort)) {
//    Serial.println(F("Data connected"));
//  } 
//  else {
//    Serial.println(F("Data connection failed"));
//    client.stop();
//    fh.close();
//    return 0;
//  }

#ifdef FTPWRITE 
  client.print(F("STOR /"));
  client.println(fileName);
#else
  client.print(F("RETR "));
  client.println(fileName);
#endif

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

#ifdef FTPWRITE
  Serial.println(F("Writing"));

  byte clientBuf[64];
  int clientCount = 0;
  while(fh.available())
  {
    clientBuf[clientCount] = fh.read();
    clientCount++;
    if(clientCount > 63)
    {
      dclient.write(clientBuf,64);
      clientCount = 0;
    }
  }
  if(clientCount > 0) dclient.write(clientBuf,clientCount);
#else
  while(dclient.connected())
  {
    while(dclient.available())
    {
      char c = dclient.read();
      fh.write(c);      
      Serial.write(c); 
    }
  }
#endif
  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"));
  fh.close();
  Serial.println(F("SD closed"));
  return 1;
}
byte eRcv(){
  byte respCode;
  byte thisByte;
  while(!client.available()) delay(1);
  respCode = client.peek();
  outCount = 0;
  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);

    if(outCount < 127)
    {
      outBuf[outCount] = thisByte;
      outCount++;      
      outBuf[outCount] = 0;
    }
  }
  if(respCode >= '4')
  {
    efail();
    return 0;  
  }
  return 1;
}
void efail(){
  byte thisByte = 0;

  client.println(F("QUIT"));
  while(!client.available()) delay(1);
  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }
  client.stop();
  Serial.println(F("Command disconnected"));
  fh.close();
  Serial.println(F("SD closed"));
}

void readSD(){
  fh = SD.open(fileName,FILE_READ);
  if(!fh)
  {
    Serial.println(F("SD open fail"));
    return;    
  }
  while(fh.available())
  {
    Serial.write(fh.read());
  }
  fh.close();
}

void printWifiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5], HEX);
  Serial.print(":");
  Serial.print(mac[4], HEX);
  Serial.print(":");
  Serial.print(mac[3], HEX);
  Serial.print(":");
  Serial.print(mac[2], HEX);
  Serial.print(":");
  Serial.print(mac[1], HEX);
  Serial.print(":");
  Serial.println(mac[0], HEX);

  // print your subnet mask:
  IPAddress subnet = WiFi.subnetMask();
  Serial.print("NetMask: ");
  Serial.println(subnet);

  // print your gateway address:
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("Gateway: ");
  Serial.println(gateway);
}

That code sure looks familiar. :wink:

The data channel connection code is commented out. What does the serial monitor show when it is not commented out?

SurferTim:
That code sure looks familiar. :wink:

The data channel connection code is commented out. What does the serial monitor show when it is not commented out?

SurferTim:
That code sure looks familiar. :wink:

The data channel connection code is commented out. What does the serial monitor show when it is not commented out?

This is the serial monitor output.

Attempting to connect to WPA SSID: Run Faster Forest
You're connected to the network
Ready. Press f or r
SD opened
Command connected
220 Welcome to the Underworld
331 Password required for test
230 Logged on
215 UNIX emulated by FileZilla
200 Type set to I
227 Entering Passive Mode (192,168,1,127,232,151)
425 Can't open data connection for transfer of "/Data_25.txt"
221 Goodbye
Command disconnected
SD closed
FTP FAIL
[code]

Didnt expect for you to reply but im glad you did.

Then it appears that wifi card can't open two connections simultaneously.

SurferTim:
Then it appears that wifi card can't open two connections simultaneously.

Darn

Is there is anther method that can be used to transfer the data, maybe HTTP POST method? Not sure how to go about starting that though

Somebody has been working on TFTP, but I didn't follow up on it. The project I needed the FTP code for has migrated to a RPi.