Problem sending files via : +FTPPUT: 1,77

Hi, everybody im having an issue with my code when im trying to send a file from an SD to a FTP Server.

It always responds with +FTPPUT: 1,77, does anybody have the same issue and find a solution ?

I share the code:

#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>
#include "eMGing_900_808.h"

#define EMGING_TX 10
#define EMGING_RX 8
#define SD_PIN 9

//SoftwareSerial eMGing(8, 10); // Pin RX(8) y TX(10)
SoftwareSerial eMGingSS = SoftwareSerial(EMGING_TX, EMGING_RX);
SoftwareSerial *eMGingSerial = &eMGingSS;

eMGing_900_808 eMGing = eMGing_900_808(4);

const char* file_to_send = "test1.txt";
String ruta_carpeta = "/ id5367 /";

char char_buffer;
String string_buffer = "";
int buffer_space = 100;
File File1;

void setup()
{
Serial.begin(eMGingSSBaud);
if (!SD.begin(SD_PIN)) {
Serial.println("inicializacion SD NO!");
return;
while(true);
}else {
Serial.println("inicializacion SD OK.");
}

audio.CSPin = SD_PIN;
eMGingSerial->begin(19200);

if (! eMGing.begin(*eMGingSerial)) {
Serial.println(F("No se encontro el shield"));
while (1);
}
Serial.println(F("El Shield eMGing esta OK"));
void loop()
{
openfile();
delay(4000);
gprs_modem_function ();
}

void inicializacion()
{
Serial.println("ESPERANDO COMANDOS AT");
delay(1000);
enviarAT("AT", "OK", 1000);
delay(100);
enviarAT(apn, "OK", 1000);
delay(100);
enviarAT("AT+SAPBR=1,1", "OK", 2000);
delay(2000);
enviarAT("AT+SAPBR=2,1", "OK", 1000);
delay(100);
enviarAT("AT+HTTPINIT", "OK", 1000);
delay(100);
enviarAT("AT+HTTPPARA="CID",1", "OK", 1000);
delay(100);
enviarAT("AT+HTTPSSL=1", "OK", 1000);
delay(100);
}

int enviarAT(String ATcommand, char* resp_correcta, unsigned int tiempo)
{
int x = 0;
int numero;
bool correcto = 0;
char respuesta[250];
unsigned long anterior;

memset(respuesta, '\0', 100); // Inicializa el string
delay(100);
while ( eMGing.available() > 0) eMGing.read(); // Limpia el buffer de entrada
eMGing.println(ATcommand); // Envia el comando AT
x = 0;
anterior = millis();
// Espera una respuesta
do {
// si hay datos el buffer de entrada del UART lee y comprueba la respuesta
if (eMGing.available() != 0)
{
respuesta[x] = eMGing.read();
x++;
// Comprueba si la respuesta es correcta
if (strstr(respuesta, resp_correcta) != NULL)
{
correcto = 1;
}
}
}
// Espera hasta tener una respuesta
while ((correcto == 0) && ((millis() - anterior) < tiempo));
Serial.println(respuesta);
}

void cleanBuffer()
{
delay( 250 );
while (eMGing.available() > 0)
{
eMGing.read(); // Clean the input buffer delay(50);
}
}

void openfile()
{

File1 = SD.open(file_to_send);
if (File1) {
Serial.println("Abriendo archivo: " + String(file_to_send) + " terminada.");
}else {
Serial.println("Error al abrir " + String(file_to_send));
while(true);
}
}
byte gprs_modem_function (){
byte reply = 1;
int i = 0;
while (i < 15 && reply == 1){ //Try 10 times...
reply = sendATcommand("AT+CREG?","+CREG: 0,1","ERROR", 1000);
i++;
delay(1000);
}
if (reply == 0){
reply = sendATcommand("AT+SAPBR=3,1,"Contype","GPRS"","OK","ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+SAPBR=3,1,"APN","internet.gprs.unifon.com.ar"", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+SAPBR=3,1,"USER",""", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+SAPBR=3,1,"PWD",""", "OK", "ERROR", 1000);
if (reply == 0){
reply = 2;
i = 0;
while (i < 3 && reply == 2){ //Try 3 times...
reply = sendATcommand("AT+SAPBR=1,1", "OK", "ERROR", 10000);
if (reply == 2){
sendATcommand("AT+SAPBR=0,1", "OK", "ERROR", 10000);
}
i++;
}
if (reply == 0){
reply = sendATcommand("AT+SAPBR=2,1", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPCID=1", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPSERV="xxx.xxx.xxx.xxx"", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPPORT=21", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPUN="xxxx"", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPPW="xxxxxT"", "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPPUTNAME="" + String(file_to_send) + """, "OK", "ERROR", 1000);
if (reply == 0){
reply = sendATcommand("AT+FTPPUTPATH="" + String (ruta_carpeta) + """, "OK", "ERROR", 1000);
if (reply == 0){
unsigned int ptime = millis();
reply = sendATcommand("AT+FTPPUT=1", "+FTPPUT: 1,1", "+FTPPUT: 1,6", 60000);
Serial.println("Time: " + String(millis() - ptime));
if (reply == 0){
if (File1) {
int i = 0;
delay(2000);
while (File1.available()>0) {
char_buffer = File1.read();
string_buffer.concat(char_buffer);
i++;

if (i == buffer_space) {
sendATcommand("AT+FTPPUT=2," + String(buffer_space), "AT+FTPPUT=2,10", "ERROR", 1000);
sendATcommand(string_buffer, "OK", "ERROR", 5000);
Serial.println(string_buffer);
string_buffer = "";
i = 0;
}
}
if (string_buffer != ""){
sendATcommand("AT+FTPPUT=2," + String(i), "AT+FTPPUT=2,10", "ERROR", 1000);
sendATcommand(string_buffer, "OK", "ERROR", 5000);
sendATcommand("AT+FTPPUT=2,0", "OK", "ERROR", 1000);
}
File1.close();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return reply;
}
byte sendATcommand(String ATcommand, String answer1, String answer2, unsigned int timeout){
byte reply = 1;
String content = "";
char character;

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

//Send the atcommand to the modem
eMGing.println(ATcommand);
delay(100);
unsigned int timeprevious = millis();
while((reply == 1) && ((millis() - timeprevious) < timeout)){
while(eMGing.available()>0) {
character = eMGing.read();
content.concat(character);
Serial.print(character);
delay(10);
}
//Stop reading conditions
if (content.indexOf(answer1) != -1){
reply = 0;
}else if(content.indexOf(answer2) != -1){
reply = 2;
}else{
//Nothing to do...
}
}
return reply;
}

If someone can help me with this i would so gratful.

Thanks.