Send small text file over ftp by sim (with APN but NO GPRS)

Hi all.
I have a MKR NB 1500 model.
I have an internet connection with a vodafone sim, with the apn (web.omnitel.it) and NO GPRS connection, I think because now it is not supported by the telephone operator.
But it's not a problem, I can connect to the web, read a web page and download content (via 3G or 4G).

I need a way to upload a small text file (.txt or .csv) to an ftp server.

All the sketches and libraries I've found are for gprs connection or via ethernet or wireless.

But I need to put the file on ftp server via sim connection.

Please can someone help me?
Can you tell me about the road to it? And tell me the library and an example sketch?

Thank you very much!

When you make an ethernet or wireless connection, it enables TCP/IP connections. FTP uses TCP/IP, so if you can make a wireless connection, you can run an FTP client, connect to an FTP server, and perform transfers. What you are looking for, is an FTP client.

It has nothing to do with the connection, GPRS, or the SIM. Except that you need it, to connect to the internet.

Exact!
I agree.
But I used the FTPClient_Generic.h library and reading its code, it seems that it expects to work only connected via ethernet or wireless... however it doesn't work for me, when I open a connection my sketch stops at the method: ftp.OpenConnection( ); and it doesn't go on anymore.

Bottom there is my code.

Thankyou for the reply.

/*
  Web client

  This sketch connects to a website through a MKR NB 1500 board. Specifically,
  this example downloads the URL "http://example.org/" and
  prints it to the Serial monitor.

  Circuit:
   - MKR NB 1500 board
   - Antenna
   - SIM card with a data plan

  created 8 Mar 2012
  by Tom Igoe
*/

// libraries
#include <MKRNB.h>
#include <FTPClient_Generic.h>

#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = SECRET_PINNUMBER;

// initialize the library instance
NBClient client;
GPRS gprs;
NB nbAccess;

// URL, path and port (for example: example.org)
char server[] = "example.org";
char path[] = "/";
int port = 80; // port 80 is the default for HTTP

// FTP side 
char ftp_server[] = "94.*********";
char ftp_user[]   = "*******";
char ftp_pass[]   = "******";
char dirName[]    = "/test2";

// FTPClient_Generic(char* _serverAdress, char* _userName, char* _passWord, uint16_t _timeout = 10000);
FTPClient_Generic ftp (ftp_server, ftp_user, ftp_pass, 60000);

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting Arduino web client.");
  // connection state
  boolean connected = false;

  // After starting the modem with NB.begin()
  // attach to the GPRS network with the APN, login and password
  while (!connected) {
    if ((nbAccess.begin(PINNUMBER, "web.omnitel.it") == NB_READY) 
        ) {
      connected = true;
      Serial.println("connected");
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("pre ftp connection");
  //ftp.GetFTPAnswer();
  ftp.OpenConnection();
  Serial.println("post ftp connection");


  //Change directory
  ftp.ChangeWorkDir(dirName);
  Serial.println("post dir");

  
  // Get the file size
  String       list[128];
  // Get the directory content in order to allocate buffer
  // my server response => type=file;modify=20190101000010;size=18; helloworld.txt
  ftp.InitFile(COMMAND_XFER_TYPE_ASCII);
  ftp.ContentListWithListCommand("", list);
  Serial.println(sizeof(list));

  for (uint16_t i = 0; i < sizeof(list); i++)
  {
    if (list[i].length() > 0)
      Serial.println(list[i]);
    else
      break;
  }

  ftp.CloseConnection();

}

void loop() {
}

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.