Git Product home page Git Product logo

ftp-server-for-esp8266-esp32-and-pybd's Introduction

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

ftp-server-for-esp8266-esp32-and-pybd's People

Contributors

iabdalkader avatar jdtsmith avatar robert-hh avatar wieck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ftp-server-for-esp8266-esp32-and-pybd's Issues

timeout if no one connects

Hi,

ftp.py are pretty useful for me. I just want "import ftp" a few seconds in my script and if no one connect it breaks and go on further..

is it possible somewhere in code to define a timeout ?

thanks

regards

Err messages I don't understand

REPL outputs "

uftpd.start()
Traceback (most recent call last):
File "", line 1, in
File "uftpd.py", line 413, in start
OSError: 23

"
Linux CLI outputs"
graham@graham-SonyVaio ~ $ ftp 192.168.0.25
ftp: connect: Connection timed out
ftp>"

I'd really like to be able to just edit Phyton files in Notepad ++ and just save over ftp using NppFTP (http://ashkulz.github.io/NppFTP/)

Hope someone else has managed to get this working on an ESP32 and can give me a pointer. I'm new to python and haven't got a clue what to do about these error messages.

out of memory on ESP8266

Unfortunately I get a mem error on the ESP8266. Added uftp.py + a simple main.py with only
import uftpd in it. Result:

MemoryError: memory allocation failed, allocating 1674 bytes
MicroPython v1.13 on 2020-09-11; ESP module with ESP8266

Automatically send file when connected

Is there any way to send a file automatically when ftp connection is established? When I started ftp via import ftp command, I want to send a specific file then stop the connection everytime. I don't want to control download/upload mechanism from computer. ESP32 should handle it by itself.
I'm recording sound with my ESP32 for 3s. After the record finished, I'm looking for a way to send it to my computer automatically.

support ethernet interface

Seems it doesn't support the Ethernet interface.

Here's how I start the Ethernet network on my Olimex ESP32-EVB.

import network
import machine
eth_if = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power = machine.Pin(17), phy_type = network.PHY_LAN8720, phy_addr=0)
eth_if.active(1)
eth_if.ifconfig()
('192.168.33.153', '255.255.255.0', '192.168.33.1', '192.168.33.1')

Then start uftpd with:

import uftpd

I'm able to connect to the server now, but unable to list dir or transfer. Using Filezilla on Win7. Set mode passive, max connections=1.

I see the part of the code that is tied to using the WLAN interface
https://github.com/robert-hh/FTP-Server-for-ESP8266-and-ESP32/blob/be5b27a47d71c4b93fdcc302bfce9b045515d622/uftpd.py#L428

and
https://github.com/robert-hh/FTP-Server-for-ESP8266-and-ESP32/blob/be5b27a47d71c4b93fdcc302bfce9b045515d622/ftp.py#L124

I'll try hacking it to work with LAN now, but I'm new at python, so I'd appreciate a proper fix.

uftpd does not 'assume QUIT' when client disconnected from AP.

example code:

import network
from time import sleep_ms
from machine import reset, WDT
import uftpd

ap = network.WLAN( network.AP_IF )
ap.config( authmode=4 ,password='12345678' )
ap.active(True)

uftpd.start(port=2121,verbose=1,splash=True)
wdt = WDT(timeout=120_000)
while True:
    sleep_ms( 60_000 )
    if uftpd.client_list:
        print('')
        print('wdt feed', uftpd.client_list )
        print('')
        wdt.feed()
    else:
        print('')
        print('no client connected!', uftpd.client_list )
        print('')

when client still connected to AP but on idle connection, uftpd will 'assume QUIT' after session time out.

FTP Data connection with: 192.168.4.2

wdt feed [<FTP_client object at 3ffe5930>]

*** No data, assume QUIT

no client connected! []

if client disconnected from AP before session timeout, uftpd did not 'assume QUIT':

FTP Data connection with: 192.168.4.2

wdt feed [<FTP_client object at 3ffe5ed0>]

wdt feed [<FTP_client object at 3ffe5ed0>]

wdt feed [<FTP_client object at 3ffe5ed0>]

tried using:

MicroPython v1.19.1-608-gb52fe52d3 on 2022-11-03; ESP32 module with ESP32
Type "help()" for more information.

Transfer files named with Chinese characters

Everyting works great!

but when I try to send file named with Chinese characters the server log shows as follow:

FTP Data connection with: 
Command=NOOP, Payload=
Command=CWD, Payload=/
Command=TYPE, Payload=I
Command=PASV, Payload=
Exception in exec_ftp_command: 
---[Errno 104] ECONNRESET(I print this line myself)
*** No data, assume QUIT

just use Windows file explorer as client and the progress bar stuck for a long time and then saids timeout
and then the server is also cannot be accessed
(for now I call restart after log_msg(1, "*** No data, assume QUIT") to continue use the server

At first i guess it is the encoding is not right so I tried "gbk, gb2312" at around line 193 still not working

I'm pretty new in both mpy and ftp sorry to open an issue for this and thanks for the time.

Uploads not working on pyboard-D

I'm using uftp and can connect successfully, traverse directories and even download files but any uploads fail with the response "550 Fail".
The filesystem still has space, micropython is version 1.15 nightly, pyboard is connected to the PC, webrepl is active but I don't even run any scripts.
Filezilla is set up for one connection, the same way ftp_thread.py works on my esp32, which I use regularly to push updates.

Compiling not truly necessary

I've included uftpd.py under lib/ and imported and run it without problems on an ESP32. The warning on the README might scare people away who could use it without rolling their own firmware with frozen in byte code!

Can I restrict client to certain directory ?

I want to specify certain directory to clients not the root "/".
I tried modify cwd:

class FTP_client:
    self.cwd = '/user_dir'

It works okay on Windows file Explorer but not well on android clients(it still access the very root "/" dir)
Also failed in modifying method :
def get_absolute_path(self, cwd, payload):
or maybe i write it wrong can you show me how to modify this.
Thanks for the time.

can just run as a ftp client

I test your project, ftp server is work on esp32, thank you very much.

and I see your code have FTP_client, can just start a ftp client? no ftp server.

Could not start transfer error

Hi Robert,

The uftpd has worked well with my esp32 until today. FileZilla failed to upload the files, no matter how I tried (restart the esp32, plug and unplug the usb cable etc.). The error message showed in the FileZilla console as below.

Response:	150 Opened data connection.
Response:	550 Fail
Error:	File transfer failed

I can see the file being created but the file size is 0 bytes.

The firmware version:
MicroPython v1.11-182-g7c15e50eb on 2019-07-30; ESP32 module with ESP32

What could be wrong? The file system corrupted?

Thanks,
Kaiyuan

Pycom ftp

Do you happen to know where the source for the FTP
server used in pycom?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.