Skip to content

Commit

Permalink
uftpd.py: Implement SITE for exec'd statements.
Browse files Browse the repository at this point in the history
By @jdsmith

Various FTP servers implement SITE "to provide services to a client that
may not be universally supported by all FTP clients". This small
addition implements a SITE command which simply exec's Python
statements. Since FTP commands may not contain newlines, the commany
payload shall contain \x00 characters as line ends, whcih are
substituted by \n.

The only catch is that if the user supplies a SITE command which
blocks when exec'd, uftpd blocks as well.
  • Loading branch information
robert-hh committed Mar 19, 2021
2 parents 5691871 + b1d927c commit 44973b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -13,6 +13,8 @@ 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
Expand All @@ -25,9 +27,13 @@ authentication may be added easily, if required.
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.
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.
- The server uses a special setsocket option, which was introduced for webrepl
and registers a callback handler. Both webrepl and uftpd use this mechanism and
register their own exclusive handler. Therefore you canot use both at the same time.


## Start-up
Expand Down
6 changes: 6 additions & 0 deletions uftpd.py
Expand Up @@ -364,6 +364,12 @@ def exec_ftp_command(self, cl):
cl.sendall('250 OK\r\n')
except:
cl.sendall('550 Fail\r\n')
elif command == "SITE":
try:
exec(payload.replace('\0','\n'))
cl.sendall('250 OK\r\n')
except:
cl.sendall('550 Fail\r\n')
else:
cl.sendall("502 Unsupported command.\r\n")
# log_msg(2,
Expand Down

0 comments on commit 44973b2

Please sign in to comment.