Post on ftp Server using Arduino GSM m10 shield

I've been trying to upload a file from my SD shield to my ftp server using the GSM shield. First I tried to alter the ftp server ethernet shield code posted on the website but it doesn't work. If anyone has an answer for this please do tell. This is the code

#include <SD.h>
#include <GSM.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 8;

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN       "epc.tmobile.com"  // replace your GPRS APN
#define GPRS_LOGIN     ""     // replace with your GPRS login
#define GPRS_PASSWORD  ""  // replace with your GPRS password

// initialize the library instance:
GSMClient client;
GSMClient dclient;
GPRS gprs;
GSM gsmAccess(true);

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
// IPAddress server(216,52,233,121);    // numeric IP for api.pachube.com
char server[] = "stginternational.org";      // name address for pachube API

char outBuf[128];
char outCount;

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

void setup()
{
  Serial.begin(9600);
  Serial.print("Intializing SD Card....");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10,OUTPUT);

 if(SD.begin(chipSelect) == 0)
  {
    Serial.println(F("SD init fail"));
    //Stop Don't do anything more
    return;    
  }
  Serial.println("card initialized.");
  // connection state
  boolean notConnected = true;
  boolean  GsmConnect=true;
  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while(GsmConnect)
  { 
   if(gsmAccess.begin(PINNUMBER)==GSM_READY) 
   {
     GsmConnect=false;
     Serial.println("Has Service");
     delay(1000);
   }
   else
   {
     Serial.println("No Service");
     delay(1000);
   }
  }
  while(notConnected)
  {
    if(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)
    {
      notConnected = false;
      Serial.print("connected");
    }
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  
  digitalWrite(10,HIGH);
  delay(2000);
  Serial.println("done");
}

void loop()
{
   // make a string for assembling the data to log:
  String dataString = "";

  // read sensors and append to the string:
  dataString= "hie soon we will have sensors";

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
Serial.println("InLoop");
   
    if(doFTP()) Serial.println(F("FTP OK"));
    else Serial.println(F("FTP FAIL"));
  

}

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,21)) {
    Serial.println(F("Command connected"));
  } 
  else {
    fh.close();
    Serial.println(F("Command connection failed"));
    return 0;
  }

  if(!eRcv()) return 0;

  client.println(F("username ftp server"));

  if(!eRcv()) return 0;

  client.println(F("password"));

  if(!eRcv()) return 0;

  client.println(F("SYST"));

  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[4] << 8;
  loPort = array_pasv[5] & 255;

  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();
}

I then also tried using the Quectel ftp AT command book, but my communication fails when I try and upload the file.

#include <SD.h>
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3);
const int chipSelect = 8;
int8_t answer;
int onModulePin= 2;

char aux_str[50];

char file_name[ ]="DATALOG.txt";

void setup(){
  delay(5000);
    // SD function
    Serial.begin(9600);
    pinMode(chipSelect, OUTPUT);
    pinMode(10, OUTPUT);  // SD library to work
    digitalWrite(10,HIGH);
    Serial.print("Initializing SD card...");
    if (!SD.begin(chipSelect)) 
    {
    Serial.println("Card failed, or not present");
    return;
    }
    Serial.println("card initialized.");
    File dataFile = SD.open("datalog.txt", FILE_READ);
    if (dataFile)
      Serial.println(" datalog.txt is opened in read mode.");
    // GSM function
    pinMode(onModulePin, OUTPUT); 
    Serial1.begin(9600); 
    delay(3000);
    
    sendATcommand("AT", "OK", 5000);
    Serial.println("GSM modem working!");
    delay(3000);
    
    // waits for signal
    while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || 
            sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
    
    // sets APN, user name and password
   // sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"airtelgprs.com\"", "OK", 2000);
    // ther is no username and password for my GPRS connection so I commented out this line
    //sendATcommand("AT+CSOCKAUTH=1,1,\"\",\"\"", "OK", 2000);
    
    // sets the paremeters for the FTP server
    sendATcommand("AT+QIFGCNT=1,\"epc.tmobile.com","OK",2000);
    sendATcommand("AT+QFTPUSER= \"user ftp","OK",2000);
    sendATcommand("AT+QFTPPASS= \"password","OK",2000);
    sendATcommand("AT+QFTPOPEN=\"ftp server\",21","OK",2000);
   
    
    // the file must be in the current directory
     sendATcommand("AT+QFTPCFG= 4,\"/UFS/","OK",2000);
     sendATcommand("AT+QFTPPATH= \"/","OK",2000);
    //  sendATcommand("AT+QFTPPUT= "file_name",1587,200","OK",2000);
    sprintf(aux_str, "AT+QFTPPUT=\"%s\",0", "DATALOG.TXT");
    answer = sendATcommand(aux_str, "+QFTPPUT: 1587", 60000);
    
    if (answer == 1)
    {        
        Serial.println("Upload done");    
    }
    else
    {
        Serial.println("Upload fail");    
    }
   

}
void loop(){
    
    

}

void power_on(){

    uint8_t answer=0;
    
    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);
    
        // waits for an answer from the module
        while(answer == 0){    
            // Send AT every two seconds and wait for the answer
            answer = sendATcommand("AT", "OK", 2000);    
        }
    }
    
}


unsigned char sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout)
{

    unsigned char x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string

    delay(100);

    while( Serial1.available() > 0) Serial1.read();    // Clean the input buffer

    Serial1.println(ATcommand);    // Send the AT command 


        x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial1.available() != 0){    
            response[x] = Serial1.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer1) != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }
    while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}

Could you solve the problem, because I am having the same problem right now.