• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Small FTP server for ESP8266/ESP32/PYBD on the MicroPython platform

uftpd: small FTP server for ESP8266, ESP32 and Pyboard D

Intro

Based on the work of chrisgp - Christopher Popp and pfalcon - Paul Sokolovsky Christopher made a first uftp server script, which runs in foreground. Paul made webrepl with the framework for background operations, which then was used also by Christopher to implement his utelnetsever code. My task was to put all these pieces together and assemble this uftpd.py script, which runs in background and acts as ftp server. Due to its size, for ESP8266 it either has to be integrated into the flash image as frozen bytecode, by placing it into the esp8266/modules folder and performing a rebuild, or it must be compiled into bytecode using mpy-cross and loaded as an .mpy file. The frozen bytecode variant is preferred.

Limitations

The server has some limitations:

  • Binary mode only
  • Limited multi-session support. The server accepts multiple sessions, but only one session command at a time is served while the other sessions receive a 'busy' response, which still allows interleaved actions.
  • No user authentication. Any user may log in without a password. User authentication may be added easily, if required.
  • Not all ftp commands are implemented.
  • ESP8266 is NOT a multitasking platform and the system calls are NOT re-entrant. Even when the ftp server sits in background and can serve requests, no foreground tasks should run at that time, especially if they execute system calls. The effects is hardly to predict, although most of the time the device simply crashes. Also in turn, when using the SITE command, the code in the payload MUST NOT be blocking, because that will block the device.
  • ESP32 The server is supported from version='v1.9.3-575 on. That is the version which introduced webrepl.

Start-up

You'll start the server with:

import uftpd

The service will immediately be started at port 21 in silent mode. You may stop the service then with:

uftpd.stop()

When stopped or not started yet, start it manually with:

uftpd.start([port = 21][, verbose = level]) or uftpd.restart([port = 21][, verbose = level])

port is the port number (default 21) verbose controls the level of printed activity messages, values 0 .. 2

You may use uftd.restart([port = 21][, verbose = level]) as a shortcut for uftp.stop() and uftpd.start().

Coverage

The server works well with most dedicated ftp clients, and most browsers and file managers. These are test results with an arbitrary selected set:

Linux

  • ftp: works for file & directory operations including support for the m* commands
  • filezilla, fireftp: work fine, including loading into the editor & saving back. Take care to limit the number of data session to 1.
  • Nautilus: works mostly, including loading into the editor & saving back. Copying multiple files at once to the esp8266 fails, because nautilus tries to open multiple sessions for that purpose. Configure Nautilus with dconf-editor to show directory count for local dirs only. Once mounted, you can even open a terminal at that spot. The path is something like: /run/user/1000/gvfs/ftp:host=x.y.y.z.
  • Thunar: works fine, including loading & saving of files. directly into e.g. an editor & saving back.
  • Dolphin, Konqueror: work fine most of the time, including loading directly into e.g. an editor & saving back. But no obvious disconnect.
  • Chrome, Firefox: view/navigate directories & and view files

Mac OS X, various Versions

  • ftp: works like on Linux
  • Chrome, Firefox: view/navigate directories & and view files
  • FileZilla, FireFtp, Cyberduck: Full operation, once proper configured (see above). Configure Cyberduck to transfer data in the command session.
  • Finder: Fails. It connects, but then locks in the attempt to display the top level directory repeating attempts to open new sessions. Finder needs full multi-session support, and never closes sessions properly.
  • Mountainduck: Works well, including proper disconnect when closing.

Windows 10 (and Windows XP)

  • ftp: supported. Be aware that the Windows variant of ftp differs slightly from the Linux variant, but the most used commands are the same.
  • File explorer: view/navigate directories & and copy files. For editing files you have to copy them to your PC and back. Windows explorer does not always release the connection when it is closed, which just results in a silent connection, which is closed latest when Windows is shut down.
  • FileZilla, FireFtp, Cyberduck: Full operation, once proper configured (see above). Configure Cyberduck to transfer data in the command session.
  • WinSCP: works fine
  • NppFTP - FTP extension to Notepad++: Works fine and is very convenient.
  • Mountainduck: Works to some extent, but sometimes stumbles and takes a long time to open a file.

Android

  • ftp inside the terminal emulator termux: full operation.
  • ftp-express
  • Chrome: view/navigate directories & and view files

IOS 9.1

  • FTP Client lite: works flawless

Windows 10 mobile

  • Metro file manager: Works with file/directory view & navigate, file download, file upload, file delete, file rename. Slow and chaotic sequence of FTP commands. Many unneeded re-login attempts.

Conclusion: All dedicated ftp clients work fine, and most of the file managers too.

Trouble shooting

The only trouble observed so far was clients not releasing the connections. You may tell by the value of uftp.client_list, which should be empty if no client is connected, or by issuing the command rstat in ftp, which shows the number of connected clients. In that case you may restart the server with uftpd.restart(). If uftd.client_busy is True when no client is connected, then restart the server with with uftpd.restart(). If you want to see what happens at the server, you may set verbose to 2. Just restart it with uftpd.restart(verbose = 1), or set uftpd.verbose_l = 1, and uftpd.verbose_l = 0 to stop control messages again.

Files

  • uftpd.py: Server source file for ESP8266 and ESP32 from version='v1.9.3-575 on
  • ftp.py: Simple version of the ftp server, which works in foreground. This can be used with all Micorpython versions. It terminates when the client closes the session. Only a single session is supported by this variant.
  • README.md: This one

More Repositories

1

Micropython-Editor

Small on-board editor for PyBoard, WiPy, ESP8266, ESP32, RP2040, W60x, XBEE 3, Sipeed K210, as well as PyCom and Adafruit devices written in Python
Python
217
star
2

SH1106

MicroPython driver for the SH1106 OLED controller
Python
156
star
3

BME280

Micropython driver for the BME280 sensor, target platform Pycom devices
Python
100
star
4

ads1x15

Micropython driver for ADS1115 and ADS1015
Python
90
star
5

Shared-Stuff

Various files for MicroPython devices
Python
47
star
6

BME680-Micropython

Micropython driver for the BME680 sensor
Python
32
star
7

SSD1963-TFT-Library-for-PyBoard-and-RP2040

SSD1963 TFT Library for PyBoard and Raspberry Pi PICO
Python
29
star
8

RP2040-Examples

Example code for the RP2040 using MicroPython
Python
28
star
9

BMP085_BMP180

Micropython module for the BMP085 and BMP180 sensors
Python
18
star
10

XPT2046-touch-pad-driver

A driver for the XPT2046 touch pad controller used in many TFT modules
Python
16
star
11

QMC5883

Python class for the QMC5883 Three-Axis Digital Compass IC
Python
12
star
12

Onewire_DS18X20

Classes for driving the DS18x20 sensor with the onewire protocol for Pycom MicroPython
Python
12
star
13

K210-Stuff

Various file for the Sipeed MaixPy K210
C
12
star
14

ATTiny-Watchdog-for-MicroPython

ATTinyx5 based watchdog timer e.g. for MicroPython devices
C++
10
star
15

SI7021

SI7021: Simple class for the SI7021 temperature and relative humidity sensor
Python
9
star
16

INA219

INA219 Micropython driver
Python
9
star
17

owonread

Get screen shots and track data data from Owon TDS series Oscilloscopes with Linux
Python
7
star
18

WS2812

WS2812 NeoPixel driver for Pycom devices
Python
5
star
19

WM_SDK_W60X

WinnerMicro SDK for the W60x chips. Based on Version G3.04.00 with a few modifications and extensions
C
5
star
20

PYBD-Adapter

Breadboard adapter for the 1/20" pitch side connections
3
star
21

SPI_Flash

A small block device driver for using SPI flash with a VFS file system.
Python
3
star
22

MCP3201

Python class interfacing the MCP3201 AD-converter
Python
3
star
23

SHT30

MicroPython driver for the SHT3x sensor.
Python
2
star
24

wm8960

Python driver for the WM8960 codec.
Python
1
star
25

Candle

Just another candle simulation
C
1
star
26

DLV-pressure-sensor

Python
1
star