Hi,
Is there a tutorial or example code for using the Wio Terminal with the Arduino FTPClient_GENERIC FTP library?
Any help is much appreciated.
Cheers.
Hi,
Is there a tutorial or example code for using the Wio Terminal with the Arduino FTPClient_GENERIC FTP library?
Any help is much appreciated.
Cheers.
You can try this:
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <FTPClient_Generic.h>
// Replace with your network credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// FTP server credentials
const char* ftp_server = "ftp.yourserver.com";
const char* ftp_user = "your_ftp_username";
const char* ftp_password = "your_ftp_password";
WiFiClient client;
FTPClient ftp(client);
void setup() {
// Initialize serial and wait for the port to open
Serial.begin(115200);
while (!Serial) {
; // Wait for serial port to connect
}
// Attempt to connect to WiFi network
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.begin(ssid, password) != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Connect to the FTP server
if (ftp.begin(ftp_server, ftp_user, ftp_password)) {
Serial.println("Connected to FTP server");
// List files on the FTP server
ftp.list("/", Serial);
// Upload a file
if (ftp.upload("/remote/path/file.txt", "/local/path/file.txt")) {
Serial.println("File uploaded successfully");
} else {
Serial.println("File upload failed");
}
// Download a file
if (ftp.download("/remote/path/file.txt", "/local/path/file.txt")) {
Serial.println("File downloaded successfully");
} else {
Serial.println("File download failed");
}
// Close the FTP connection
ftp.end();
} else {
Serial.println("Failed to connect to FTP server");
}
}
void loop() {
// Nothing to do here
}