Skip to content

Communication FTP

pschatzmann edited this page Oct 22, 2026 · 1 revision

Many NAS systems and routers provide their files via FTP. With TinyFTPClient (install it) your microcontroller can read audio files from an FTP server: either a single file as a stream, or a whole directory with the AudioPlayer. See Communication for the general considerations, and SMB for Windows and Samba shares.

Playing a directory: AudioSourceFTP

AudioSourceFTP (AudioTools/Disk/AudioSourceFTP.h) is an AudioSource for the AudioPlayer: it plays the files of a directory that match the extension. From player-ftp-audiokit.ino:

#include "WiFi.h"
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/Disk/AudioSourceFTP.h"

FTPClient<WiFiClient> ftp;
AudioSourceFTP<WiFiClient> source(ftp, "Music/Tracy Chapman/Matters of the Heart", "mp3");
AudioBoardStream i2s(AudioKitEs8388V1);
MP3DecoderHelix decoder;
AudioPlayer player(source, i2s, decoder);

void setup() {
  // ... connect WiFi
  WiFi.setSleep(false);
  if (!ftp.begin(IPAddress(192, 168, 1, 39), "user", "password")) stop();
  auto cfg = i2s.defaultConfig(TX_MODE);
  i2s.begin(cfg);
  player.begin();
}

void loop() { player.copy(); }

Open the FTP connection (ftp.begin()) before the player accesses the files. The file names are not kept in memory: the directory is listed on the server each time a new file is selected.

Reading a single file

An FTPFile is a Stream, so you can copy it to a decoder. From ftp-client.ino:

FTPClient<WiFiClient> client;
FTPFile file;
AudioBoardStream kit(AudioKitEs8388V1);
MP3DecoderHelix mp3;
EncodedAudioStream decoder(&kit, &mp3);
StreamCopy copier(decoder, file);

void setup() {
  // ... connect WiFi
  client.begin(IPAddress(192, 168, 1, 10), "user", "password");
  file = client.open("/data/music/Neil Young/After the Gold Rush/08 Birds.mp3");
  kit.begin();
  decoder.begin();
}

void loop() { copier.copy(); }

You can also write files to the server - e.g. to save a recording. See the TinyFTPClient documentation.

Things to consider

  • FTP sends the password in plain text - use it only in your own network.
  • The FTP server must allow passive mode, which the client uses for the data connection.

Clone this wiki locally