Error Upload File from SD card module dfrobot

hello
i need your help,
im trying to transfer csv file from dfrobot sd card to a ftp server using GSM shield sim5216A.
my reference is http://www.cooking-hacks.com/documentation/tutorials/arduino-3g-gprs-gsm-gps#step13 the code is only explaining how to transfer a file from local storage to FTP server and nothing is said about the SD card. I added the SD card initialization code and opened the text file in read mode. After this I don't know How I am supposed to proceed. here is my code,

#include <SD.h>

const int chipSelect = 10;
int8_t answer;
int onModulePin= 2;
char aux_str[50];
char file_name[]="datalog.csv";
File dataFile = SD.open(file_name, FILE_READ);

void setup(){
  delay(5000);
  Serial.begin(115200);
  pinMode(chipSelect, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Menginisialisasi kartu SD...");
  if (!SD.begin(chipSelect))
  {
    Serial.println("Kartu tidak tersedia");
    return;
  }
  Serial.println("Inisialisasi Sukses. Kartu tersedia");
  dataFile = SD.open(file_name);
  if (dataFile){
    Serial.println(" datalog.csv dibuka dalam posisi membaca.");
    
    power_on();
    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
    answer=sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"internet\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CSOCKAUTH=1,0,\"user_name\",\"password\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPUN=\"myusername\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPPW=\"mypassword\"", "OK", 2000);
    Serial.println(answer);
    // sets the paremeters for the FTP server and the path
    answer=sendATcommand("AT+CFTPSERV=\"myserver.com\"", "OK", 2000);
    Serial.println(answer);
    
    //String ftp = "AT+CFTPPUTFILE=";
    //answer=sendATcommand("AT+CFTPPUTFILE="dataFile, "OK", 2000);
    
    sprintf(aux_str, "AT+CFTPPUTFILE=\"%s\",0", file_name);
    answer = sendATcommand(aux_str, "+CFTPPUTFILE: 0", 6000);
    Serial.println(answer);
    
    if (answer == 1)
    {        
        Serial.println("Upload done");    
    }
    else
    {
        Serial.println("Upload fail");    
    }
  }
  //sendATcommand("AT", "OK", 5000);
   
   
}


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


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

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

    memset(response, '\0', 100);    // Initialize the string
    
    delay(100);
    
    while( Serial.available() > 0) Serial.read();    // Clean the input buffer
    
    Serial.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial.available() != 0){    
            response[x] = Serial.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;
}

and this is the out put I am getting.

Menginisialisasi kartu SD...Inisialisasi Sukses. Kartu tersedia
 datalog.csv dibuka dalam posisi membaca.
AT
GSM modem working!
AT+CREG?
AT+CGSOCKCONT=1,"IP","internet"
1
AT+CSOCKAUTH=1,0,"user_name","password"
0
AT+CFTPUN="myusername"
1
AT+CFTPPW="mypassword"
1
AT+CFTPSERV="myserver.com"
1
AT+CFTPPUTFILE="datalog.csv",1
0
Upload fail

please help me,
and thank you very much.

Your server doesn't support active FTP mode, so you have to set passive mode on the client:

    answer=sendATcommand("AT+CFTPMODE=1", "OK", 2000);
    Serial.println(answer);

Maybe that helps.

Else please provide a link to the modules documentation.

pylon:
Your server doesn't support active FTP mode, so you have to set passive mode on the client:

    answer=sendATcommand("AT+CFTPMODE=1", "OK", 2000);

Serial.println(answer);




Maybe that helps.

Else please provide a link to the modules documentation.

still same error appear, upload fail.

here my updated code :

#include <SD.h>

const int chipSelect = 10;
int8_t answer;
int onModulePin= 2;
char aux_str[50];
char file_name[]="datalog.csv";
File dataFile = SD.open(file_name, FILE_READ);

void setup(){
  delay(5000);
  Serial.begin(115200);
  pinMode(chipSelect, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Menginisialisasi kartu SD...");
  if (!SD.begin(chipSelect))
  {
    Serial.println("Kartu tidak tersedia");
    return;
  }
  Serial.println("Inisialisasi Sukses. Kartu tersedia");
  dataFile = SD.open(file_name);
  if (dataFile){
    Serial.println(" datalog.csv dibuka dalam posisi membaca.");
    
    power_on();
    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
    answer=sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"internet\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CSOCKAUTH=1,0,\"user_name\",\"password\"", "OK", 2000);
    Serial.println(answer);
    // sets the paremeters for the FTP server and the path
    answer=sendATcommand("AT+CFTPSERV=\"myserver.com\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPPORT=21", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPMODE=1", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPUN=\"myusername\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPPW=\"mypassword\"", "OK", 2000);
    Serial.println(answer);
    
    //String ftp = "AT+CFTPPUTFILE=";
    //answer=sendATcommand("AT+CFTPPUTFILE="dataFile, "OK", 2000);
    
    sprintf(aux_str, "AT+CFTPPUTFILE=\"%s\",0", file_name);
    answer = sendATcommand(aux_str, "+CFTPPUTFILE: 0", 6000);
    Serial.println(answer);
    
    if (answer == 1)
    {        
        Serial.println("Upload done");    
    }
    else
    {
        Serial.println("Upload fail");    
    }
  }
  //sendATcommand("AT", "OK", 5000);
   
   
}


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


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

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

    memset(response, '\0', 100);    // Initialize the string
    
    delay(100);
    
    while( Serial.available() > 0) Serial.read();    // Clean the input buffer
    
    Serial.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial.available() != 0){    
            response[x] = Serial.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;
}

and respond from serial monitor is :

AT+CGSOCKCONT=1,"IP","internet"
1
AT+CSOCKAUTH=1,0,"user_name","password"
0
AT+CFTPSERV="myserver"
1
AT+CFTPPORT=21
1
AT+CFTPMODE=1
1
AT+CFTPUN="myusername"
1
AT+CFTPPW="mypassword"
1
AT+CFTPPUTFILE="datalog.csv",0
0
Upload fail

If I interpret your sketch correctly you're printing debug messages to the same serial interface as you use to send commands to the GSM shield. Don't you think that the module might be confused by your messages?

pylon:
If I interpret your sketch correctly you're printing debug messages to the same serial interface as you use to send commands to the GSM shield. Don't you think that the module might be confused by your messages?

recently i refer to this problem http://www.cooking-hacks.com/forum/viewtopic.php?f=20&t=4198&sid=0851ee19f8da84db373f80aaf523506b in this case, they discuss, if i use extended sd card module, i cant use AT+cftpputfile for upload to ftp but use AT+CFTPUT,

im already update my code like this :

#include <SD.h>

const int chipSelect = 10;
int8_t answer;
int onModulePin= 2;
char aux_str[50];
char file_name[]="datalog.csv";
File dataFile = SD.open(file_name, FILE_READ);
//char file_name2[]="D:/datalog.csv";

void setup(){
  delay(5000);
  Serial.begin(115200);
  pinMode(chipSelect, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Menginisialisasi kartu SD...");
  if (!SD.begin(chipSelect))
  {
    Serial.println("Kartu tidak tersedia");
    return;
  }
  Serial.println("Inisialisasi Sukses. Kartu tersedia");
  dataFile = SD.open(file_name, FILE_READ);
  if (dataFile)
  {
    Serial.println("datalog.csv dibuka dalam posisi membaca.");
    
    power_on();
    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
    answer=sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"internet\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CSOCKAUTH=1,0,\"user_name\",\"password\"", "OK", 2000);
    Serial.println(answer);
    // sets the paremeters for the FTP server
    answer=sendATcommand("AT+CFTPSERV=\"23.226.134.243\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPPORT=21", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPMODE=1", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPTYPE=I", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPUN=\"myusername\"", "OK", 2000);
    Serial.println(answer);
    answer=sendATcommand("AT+CFTPPW=\"mypassword\"", "OK", 2000);
    Serial.println(answer);
    
 
    sprintf(aux_str, "AT+CFTPPUT=\"%s\"", file_name);
    answer = sendATcommand(aux_str, "+CFTPPUT: BEGIN", 60000);
    Serial.println(answer);
    
    if (answer == 1)
    {        
        Serial.println("Upload done");    
    }
    else
    {
        Serial.println("Upload fail");    
    }
  }
  //sendATcommand("AT", "OK", 5000);
   
   
}


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


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

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

    memset(response, '\0', 100);    // Initialize the string
    
    delay(100);
    
    while( Serial.available() > 0) Serial.read();    // Clean the input buffer
    
    Serial.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial.available() != 0){    
            response[x] = Serial.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;
}

and for now, i succeed upload to server, but on my server, files have been uploaded not data from my sd card, but other data created by arduino match the name of my data but the number of bytes 0, and the file was corrupt.