FTP Server
FTP Server
Hello,
I wanted a more convenient (for me) way of managing files on my device so I implemented a prototype minimal FTP server that can run on the ESP8266. It needs more work before it is generally useful, but it's hacked together enough to handle LS, GET and PUT commands for demo purposes: https://github.com/cpopp/MicroFTPServer
Here's a screenshot showing a file listing in chrome and a command line ftp client retrieving a file
I wanted a more convenient (for me) way of managing files on my device so I implemented a prototype minimal FTP server that can run on the ESP8266. It needs more work before it is generally useful, but it's hacked together enough to handle LS, GET and PUT commands for demo purposes: https://github.com/cpopp/MicroFTPServer
Here's a screenshot showing a file listing in chrome and a command line ftp client retrieving a file
Re: FTP Server
Hello @chrisgp. That is a VERY useful script. With background operation, it will be the perfect support for file transfer, when a web console is not needed.
Tested on a Wemos D1 device, both in RAM and frozen bytecode, with command line ftp. FileZilla shows the directory, but file transfer fails on ECONNRESET.
With command line ftp, ls and get work, but put tellls if has sent xxx bytes, but the stored file is just 128 bytes long. Fixed it by
Tested on a Wemos D1 device, both in RAM and frozen bytecode, with command line ftp. FileZilla shows the directory, but file transfer fails on ECONNRESET.
With command line ftp, ls and get work, but put tellls if has sent xxx bytes, but the stored file is just 128 bytes long. Fixed it by
Code: Select all
def save_file_data(path, dataclient):
with open(path, "w") as file:
chunk = dataclient.read(128)
while len(chunk) > 0:
file.write(chunk)
chunk = dataclient.read(128)
Re: FTP Server
I made two small changes for my convenience, maybe only temporary:
- put the main code into a function, e.g. ftpserver()
- terminate the server when the client quits
That allows to change between REPL prompt and file transfer w/o rebooting the ESP8266.
I have placed the changed code here: https://github.com/robert-hh/Shared-Stuff
I know it's not git style, but this is easier than going through the PR pain.
Update: Looking at the behavior of Chrome, terminating the server if the client quits seems not appropriate, since Chrome send a quit after each dir-list, file display, ....
- put the main code into a function, e.g. ftpserver()
- terminate the server when the client quits
That allows to change between REPL prompt and file transfer w/o rebooting the ESP8266.
I have placed the changed code here: https://github.com/robert-hh/Shared-Stuff
I know it's not git style, but this is easier than going through the PR pain.
Update: Looking at the behavior of Chrome, terminating the server if the client quits seems not appropriate, since Chrome send a quit after each dir-list, file display, ....
Re: FTP Server
Glad to hear you tried it out and thanks for catching the bug saving files -- I committed that fix to my repository.
Re: FTP Server
I've added also the actual date/time values to the LIST command output, and tried to implement mkdir/rmdir/delete. The latter is not yet in my file space on the web. Sometimes the ESP crashes (reboot) when I run these commands. Not sure why.
Re: FTP Server
I just tested FireFTP extension to Firefox, which works nice, including copying, opening, editing & saving on spot. Needs a support for the NOOP command. I added it, and also support for delete, mkdir and rename. Like yesterday, I've placed that version in this spot: https://github.com/robert-hh/Shared-Stuff. Sometimes, it still blocks, but I cannot tell why.
Re: FTP Server
Hello @chrisgp. I made a few more additions to your uftpsever.py (sorry for hijacking it), wasting some time on spurious crashes, which turned out to be causes by an outdated mpy-cross. It was tested on various platforms & software pieces.
Linux:
Linux:
- ftp: works for file & directory operations w/o support for the m* commands
- nautilus, thunar, filezilla, fireftp: work fine, including loading into the editor & saving back
- Chrome: view/navigate directories & and view files
- ftp: works like on Linux
- Chrome: view/navigate directories & and view files
- Finder: connects, but locks in the attempt to display the top level directory w/o any activity visible at the server
- explorer: works fine, but for editing files you have to copy them to your PC and back.
- ftp: connects, but no files operations, since passive mode is not supported
- filezille: works as expecetd
Re: FTP Server
Nice, thanks for continuing to share your changes. Even if our implementations end up diverging it's nice to have something to compare to. I took a look at the current state of yours and it makes sense to me and my only feedback might be to not depend on the uos module to track the cwd and instead track it separately so that if it does end up running in the background it doesn't conflict if other scripts are depending on that.
Re: FTP Server
Hello @chrisgp, the point about background operation is valid. So I changed it back to your style of maintaining cwd locally. The list of tested hosts and tools is the same. Just some more observations:
- the most robust tools tested are: plain ftp, fireftp and filezilla
- the file managers besides mac finder do the job too, but with some limitations. But viewing the files & copying flles in & out works always.
- Windows file explorer does not always terminate the session when you close it.
- the most robust tools tested are: plain ftp, fireftp and filezilla
- the file managers besides mac finder do the job too, but with some limitations. But viewing the files & copying flles in & out works always.
- Windows file explorer does not always terminate the session when you close it.
Re: FTP Server
Hello all & @chrisgp, I made a few more changes:
- SYST command: returns now a value which pleases Firefox
- LIST and NLST accept as optional parameter now also filenames, with ? and * as wildcards. Now, also ftp's mput, mget and mdelete commands are supported
- APPE command supported (may be dropped)
- Chunk size for file transfers increased form 128 to 512 bytes, speeding up transfer.