I'm trying to connect my MKR WIFI 1010 to my local FTP server to upload a file through WIFI. I've tried many things but the naswer is always the same : "Not connected error".
I'm a total beginner in FTP/server and things like that.
In term of Arduino, I'm just a little better (I can use it but that's it).
I have no problem to connect to the WiFi, but all the libraries I have tested to connect to the FTP are not working.
The problem (and this is where that won't help you) is that I dunno if it is a problem on my FTP server side (I got it from my internet box), of incompatibilities between libraries and MKR 1010 or about my code (on that part i'm pretty sure it's quite OK since i'm using example).
I've tested various librairies (FTPClient Generic, Simple FTP Server and ESP32 FTP Server which does not work on MKR 1010)
Here is an example of code that is not working (I haven't put the code related to the WiFi connection since it is working well, I managed to send data to my smartphone via Blynk):
#include "Arduino.h"
#include <FTPClient_Generic.h>
#include "arduino_secrets.h"
char ftp_user[] = SECRET_USER;
char ftp_pass[] = SECRET_PASS;
char ftp_server[] = "FTP server name";
char dirName[] = "/Arduino";
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
ftp.OpenConnection();
ftp.GetFTPAnswer();
ftp.ChangeWorkDir("/Arduino");
ftp.InitFile(COMMAND_XFER_TYPE_ASCII);
ftp.NewFile("helloworld.txt");
ftp.Write("Hi, I'm a new file");
ftp.CloseFile();
String response = "";
ftp.InitFile(COMMAND_XFER_TYPE_ASCII);
ftp.DownloadString("helloworld.txt", response);
Serial.println("The file content is: " + response);
ftp.CloseConnection();
}
void loop() {
}
Would you have any hint for me please ?
Or, would you have an alternative solution since what i'm trying to do is to send sensor data to a storage place other than a SD card (directly available).
Thanks a lot,
And sorry if this is the wrong forum, I hesitated with the MKR 1010 forum.
Iforire
Hi BitSeeker,
I did not put the WiFi connection part in the code as I did not want to pollute the code. It is working and I can connect to my local WiFi.
Here the full code (many things are not useful...)
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>
#include "Arduino.h"
#include <FTPClient_Generic.h>
#include "arduino_secrets.h"
#define USING_VSFTP_SERVER true
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key index number
int status = WL_IDLE_STATUS; // the WiFi radio's status
char ftp_user[] = SECRET_USER;
char ftp_pass[] = SECRET_PASS;
char ftp_server[] = "server name";
char dirName[] = "/Arduino";
FTPClient_Generic ftp (ftp_server, ftp_user, ftp_pass, 60000);
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WEP network, SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, keyIndex, pass);
// wait 10 seconds for connection:
delay(10000);
}
// once you are connected :
Serial.print("You're connected to the network");
printWiFiStatus();
ftp.OpenConnection();
ftp.GetFTPAnswer();
ftp.ChangeWorkDir("/Arduino");
ftp.InitFile(COMMAND_XFER_TYPE_ASCII);
ftp.NewFile("helloworld.txt");
ftp.Write("Hi, I'm a new file");
ftp.CloseFile();
String response = "";
ftp.InitFile(COMMAND_XFER_TYPE_ASCII);
ftp.DownloadString("helloworld.txt", response);
Serial.println("The file content is: " + response);
ftp.CloseConnection();
unsigned long epoch;
int numberOfTries = 0, maxTries = 6;
do {
epoch = WiFi.getTime();
numberOfTries++;
}
}
void loop() {
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void printWifiData() {
// print your board'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: ");
printMacAddress(mac);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
Is the FTP server running on a local PC or in the cloud?
if local PC have you set up the firewall to allow the remote connection?
can you run a FTP client and connect to the server ?
Hi Horace.
It's local (on my Internet box) but accessible from anywhere.
I've used FileZilla to acess it, read file and create new file, as I'd like to do with the MKR 1010.
Sorry, i was not very precise in my first post...
Thanks
was this on the same PC as the server or a different machine?
rather then using the server PC name try using its IP address when connecting
it may be worth putting some Serial.println() statements in the code at critical points and then post the serial monitor output
Does your FTP server require a username/password, even if it is only 'anonymous' and a blank or some default password?
Have you checked the FTP server logs? They might provide some insight as to whether the server is seeing an attempted connection or has rejected it for some reason.
Does your FTP server require a username/password, even if it is only 'anonymous' and a blank or some default password?
Indeed, it does, I have put them in an "arduino_secrets.h" file.
Have you checked the FTP server logs? They might provide some insight as to whether the server is seeing an attempted connection or has rejected it for some reason.
Hum, indeed, I saw people doing that when they have problems with their FTP server in different forum posts. I don't know how to do, I'll check that! probably with FileZilla?
I've tried the IP adress and it did not work with the librairies I used.
The code result is that:
You're connected to the networkSSID: ***
IP Address: ***
signal strength (RSSI):-51 dBm
[FTP] ChangeWorkDir: Not connected error
[FTP] InitFile: Not connected error
[FTP] NewFile: Not connected error
[FTP] Write: Not connected error
[FTP] CloseFile: Not connected error
[FTP] InitFile: Not connected error
The file content is:
So it goes though the code, but it does not manage to connect tot he FTP server.
When I use IP adress of the FTP server, I do not even get any results from the FTP side '[FTP]'
if you are running the FileZilla FTP server there is the Administration Interface which display FTP client interactions
e.g. just run an FTP client on an ESP32
Thanks horace and BitSeeker.
I do not know about the FTP server BitSeeker, sorry.
horace, the code is indeed missing a "while" but it's my fault, I removed unecessary parts (about temperature measurements and RTC) and I did not erase it well. The code is working (no errors).
Ill try the FTP FileZilla Server as I do have the client version, thanks!
Arf, I did not manage to connect to the FTP server using FileZilla server (I managed using FileZilla client though!).
I've tried many things since I have an address in the form "ftp://name.name.com" which I can access using the FileZilla Client.
And I have a distant IP address and two ports (one for "control", the other for "data"), both are not working with the FileZilla Client.
Everything is not working with the FileZilla server, giving the errors:
Thanks everyone.
Unfortunately, it does not work for me.
I think this is a problem of my FTP server configuration since I don't even manage to connect to it using FileZilla Server.
Is there another way (easy if possible to send a file through WIFI using a MKR 1010 ? Perhaps by email every day at a certain time? Or using the MKR as a server and conneting to it via a webpage where I can download the file?