/FTP_Server_Teensy41

FTP Server for Teensy 4.x using SD, LittleFS, etc. with QNEthernet, NativeEthernet or W5x00 using Ethernet_Generic Library

Primary LanguageC++GNU General Public License v3.0GPL-3.0

FTP_Server_Teensy41

arduino-library-badge GitHub release contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of contents



Why do we need this FTP_Server_Teensy41 library

Features

This FTP_Server_Teensy41 library is modified from Arduino-Ftp-Server library to support Teensy 4.x with QNEthernet, NativeEthernet or W5x00 using Ethernet_Generic Library, and currently SDFat2. In the near future, any FS, such as PSRAM, S, (Q)SPI Flash, etc. will be supported.


Currently supported Boards

  1. Teensy 4.1 using QNEthernet, NativeEthernet or W5x00 with Ethernet_Generic Library and built-in SDCard, etc.
  2. Teensy 4.0 using W5x00 with Ethernet_Generic Library


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. Teensy core v1.56+ for Teensy 4.1
  3. QNEthernet Library version v0.14.0+ for Teensy 4.1 built-in Ethernet.
  4. NativeEthernet Library version stable111+ for Teensy 4.1 built-in Ethernet.
  5. Ethernet_Generic library v2.1.0+ to use W5x00. To install, check arduino-library-badge.

Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for FTP_Server_Teensy41, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

  1. Navigate to FTP_Server_Teensy41 page.
  2. Download the latest release FTP_Server_Teensy41-master.zip.
  3. Extract the zip file to FTP_Server_Teensy41-master directory
  4. Copy the whole FTP_Server_Teensy41-master folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO:

  1. Install VS Code
  2. Install PlatformIO
  3. Install FTP_Server_Teensy41 library by using Library Manager. Search for FTP_Server_Teensy41 in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


Packages' Patches

1. For Teensy boards

To be able to compile and run on Teensy boards, you have to copy the files in Packages_Patches for Teensy directory into Teensy hardware directory (./arduino-1.8.19/hardware/teensy/avr/boards.txt).

Supposing the Arduino version is 1.8.19. These files must be copied into the directory:

  • ./arduino-1.8.19/hardware/teensy/avr/boards.txt
  • ./arduino-1.8.19/hardware/teensy/avr/cores/teensy/Stream.h
  • ./arduino-1.8.19/hardware/teensy/avr/cores/teensy3/Stream.h
  • ./arduino-1.8.19/hardware/teensy/avr/cores/teensy4/Stream.h

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz These files must be copied into the directory:

  • ./arduino-x.yy.zz/hardware/teensy/avr/boards.txt
  • ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy/Stream.h
  • ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy3/Stream.h
  • ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.h


Original Documents

Please have a look at README_orig.md or README.md



Examples

  1. FTP_Server_SDFAT2
  2. multiFileProject


https://github.com/khoih-prog/FTP_Server_Teensy41/blob/5916a2c287b19b899eae9456c5937f522a8d6e30/examples/FTP_Server_SDFAT2/FTP_Server_SDFAT2.ino#L10-L369


2. File defines.h

https://github.com/khoih-prog/FTP_Server_Teensy41/blob/5916a2c287b19b899eae9456c5937f522a8d6e30/examples/FTP_Server_SDFAT2/defines.h#L10-L126



Debug Terminal Output Samples

1. FTP_Server_SDFAT2 on TEENSY 4.1 with QNEthernet

Following is debug terminal output when running example FTP_Server_SDFAT2 on Teensy4.1 using Built-in Ethernet and QNEthernet Library demonstrate the operation of FTP Server and SD Card using SDFat2.

Starting FTP_Server_SDFAT2 on TEENSY 4.1 with QNEthernet
FTP_Server_Teensy41 v1.1.0
Initializing SD card...
Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (Kbytes): 31452672
Volume size (Mbytes): 30715

===============================
SDCard Initialization : done.
test.txt                                      1048702    22:42  April 29, 2022
foo.txt                                            13    00:00  January 1, 1980
datalog.bin                                  41943040    00:00  January 1, 2022
index.htm                                        3810    22:50  April 29, 2022
mydatalog.txt                                      10    22:24  April 9, 2022
edit.htm.gz                                      4116    20:15  March 13, 2022
CanadaFlag_1.png                                41214    20:15  March 13, 2022
CanadaFlag_2.png                                 8311    20:15  March 13, 2022
CanadaFlag_3.jpg                                11156    20:15  March 13, 2022
favicon.ico                                      1150    22:54  April 29, 2022
graphs.js.gz                                     1971    20:15  March 13, 2022
CanadaFlag_2_1.png                               8311    22:52  April 29, 2022
ESP_AT_WM_Lite.txt                               1547    22:51  April 29, 2022
done!

=========== USE_QN_ETHERNET ===========
Initialize Ethernet using static IP => IP Address = 192.168.2.241
FTP Server Credentials => account = teensy4x, password = ftp_test
[FTP]  Ftp server waiting for connection on port  21
[FTP]  Client connected!
USER teensy4x
PASS ftp_test
[FTP]  Authentication Ok. Waiting for commands.
SYST
DELE test.txt
PORT 192,168,2,30,169,133
[FTP]  Data IP set to  192.168.2.30 , Data port set to  43397
LIST
DELE datalog.bin
PORT 192,168,2,30,135,195
[FTP]  Data IP set to  192.168.2.30 , Data port set to  34755
LIST
PORT 192,168,2,30,165,55
[FTP]  Data IP set to  192.168.2.30 , Data port set to  42295
LIST
PORT 192,168,2,30,206,193
[FTP]  Data IP set to  192.168.2.30 , Data port set to  52929
RETR index.htm
[FTP]  Sending  index.htm
PORT 192,168,2,30,182,29
[FTP]  Data IP set to  192.168.2.30 , Data port set to  46621
STOR index1.htm
[FTP]  Receiving  index1.htm
[FTP]  Transfer completed in (ms)  250 , Speed (kbytes/s)  15
QUIT
[FTP]  Disconnecting client
[FTP]  Ftp server waiting for connection on port  21

2. FTP_Server_SDFAT2 on TEENSY 4.1 with NativeEthernet

Following is debug terminal output when running example FTP_Server_SDFAT2 on Teensy4.1 using Built-in Ethernet and NativeEthernet Library demonstrate the operation of FTP Server and SD Card using SDFat2.

Starting FTP_Server_SDFAT2 on TEENSY 4.1 with NativeEthernet
FTP_Server_Teensy41 v1.1.0
Initializing SD card...
Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (Kbytes): 31452672
Volume size (Mbytes): 30715

===============================
SDCard Initialization : done.
index1.htm                                       3810    23:11  April 29, 2022
foo.txt                                            13    00:00  January 1, 1980
index.htm                                        3810    22:50  April 29, 2022
mydatalog.txt                                      10    22:24  April 9, 2022
edit.htm.gz                                      4116    20:15  March 13, 2022
CanadaFlag_1.png                                41214    20:15  March 13, 2022
CanadaFlag_2.png                                 8311    20:15  March 13, 2022
CanadaFlag_3.jpg                                11156    20:15  March 13, 2022
favicon.ico                                      1150    22:54  April 29, 2022
graphs.js.gz                                     1971    20:15  March 13, 2022
CanadaFlag_2_1.png                               8311    22:52  April 29, 2022
ESP_AT_WM_Lite.txt                               1547    22:51  April 29, 2022
done!
======== USE_NATIVE_ETHERNET ========
Using mac index = 7
Connected! IP address: 192.168.2.103
FTP Server Credentials => account = teensy4x, password = ftp_test
[FTP]  Ftp server waiting for connection on port  21
[FTP]  Client connected!
USER teensy4x
PASS ftp_test
[FTP]  Authentication Ok. Waiting for commands.
SYST
PORT 192,168,2,30,146,13
[FTP]  Data IP set to  192.168.2.30 , Data port set to  37389
LIST
DELE index1.htm
PORT 192,168,2,30,170,27
[FTP]  Data IP set to  192.168.2.30 , Data port set to  43547
STOR index1.htm
[FTP]  Receiving  index1.htm
[FTP]  Transfer completed in (ms)  2 , Speed (kbytes/s)  1905
QUIT
[FTP]  Disconnecting client
[FTP]  Ftp server waiting for connection on port  21

3. FTP_Server_SDFAT2 on TEENSY 4.0 with W5x00 using Ethernet_Generic Library

Following is debug terminal output when running example FTP_Server_SDFAT2 on Teensy4.0 using W5x00 using Ethernet_Generic Library with Large Buffer.

Starting FTP_Server_SDFAT2 on TEENSY 4.0 with W5x00 using Ethernet_Generic Library with Large Buffer
FTP_Server_Teensy41 v1.1.0
======== USE_ETHERNET_GENERIC ========
[FTP] Default SPI pinout:
[FTP] MOSI: 11
[FTP] MISO: 12
[FTP] SCK: 13
[FTP] SS: 10
[FTP] =========================
[FTP] Board : TEENSY 4.0 , setCsPin: 10
IP Address = 192.168.2.118
FTP Server Credentials => account = teensy4x, password = ftp_test
[FTP]  Ftp server waiting for connection on port  21
[FTP]  Client connected!
USER teensy4x
PASS ftp_test
[FTP]  Authentication Ok. Waiting for commands.
SYST
PORT 192,168,2,30,233,47
[FTP]  Data IP set to  192.168.2.30 , Data port set to  59695
LIST
PORT 192,168,2,30,148,131
[FTP]  Data IP set to  192.168.2.30 , Data port set to  38019


Debug

Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, change the AWS_TEENSY41_LOGLEVEL to 0

// Use this to output debug msgs to Serial
#define TEENSY41_DEBUG_PORT                 Serial

// Debug Level from 0 to 4
#define _FTP_SERVER_LOGLEVEL_               2

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of Arduino IDE, the Arduino Teensyduino core or depending libraries.

Sometimes, the library will only work if you update the Teensyduino core to the latest version because I'm always using the latest cores /libraries.


Issues

Submit issues to: FTP_Server_Teensy41 issues



TO DO

  1. Fix bug. Add enhancement
  2. Add support to to LittleFS, (Q)SPI Flash, etc. besides SD card.

DONE

  1. Initial porting and coding for Teensy 4.1 using built-in QNEthernet, NativeEthernet or W5x00 using Ethernet_Generic Library
  2. Support SD card and SDFat1, SDFat2
  3. Add debugging features.
  4. Add Table-of-Contents and Version String
  5. Fix bug incomplete downloads from server to client


Contributions and Thanks

  1. Based on and modified from Jean-Michel Gallego's Arduino-Ftp-Server library
  2. Thanks to Warren Watson to make PR in Incomplete downloads from server to client. #2 leading to the new version v1.1.0 to fix bug incomplete downloads from server to client.
gallegojm
⭐️ Jean-Michel Gallego

wwatson4506
Warren Watson


Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell other people about this library

License

  • The library is licensed under GPLv3

Copyright

  • Copyright 2014- Jean-Michel Gallego
  • Copyright 2022- Khoi Hoang