ESP32: How to send files from internal flash to PC

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
mkcastillote
Posts: 4
Joined: Mon Mar 16, 2020 10:35 am

Re: ESP32: How to send files from internal flash to PC

Post by mkcastillote » Mon Mar 16, 2020 1:36 pm

Ok thank you very much!

I already put these files boot.py, main.py, ftplib.py, and ftplib.mpy on my /home/pi/ directory since I'm using my Raspberry Pi as a Linux machine.

Now, I executed these commands on my Raspberry Pi's Terminal so that I can send those 4 files on my NodeMCU.

sudo ampy --port /dev/ttyUSB0 put boot.py
sudo ampy --port /dev/ttyUSB0 put main.py
sudo ampy --port /dev/ttyUSB0 put ftplib.py
sudo ampy --port /dev/ttyUSB0 put ftplib.mpy

After the transfer, I executed these commands on my Raspberry Pi's Terminal.

sudo ampy --port /dev/ttyUSB0 run boot.py
sudo ampy --port /dev/ttyUSB0 run main.py

NOTE: main.py is just a simple script for doing an FTP, the code came from the official python ftplib.

After I run the 'main.py', I still got some errors. Here is the error.

Traceback (most recent call last):
File "/usr/local/bin/ampy", line 8, in <module>
sys.exit(cli())
File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/ampy/cli.py", line 337, in run
output = board_files.run(local_file, not no_output)
File "/usr/local/lib/python3.7/dist-packages/ampy/files.py", line 303, in run
out = self._pyboard.execfile(filename)
File "/usr/local/lib/python3.7/dist-packages/ampy/pyboard.py", line 273, in execfile
return self.exec_(pyfile)
File "/usr/local/lib/python3.7/dist-packages/ampy/pyboard.py", line 267, in exec_
raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 1, in <module>\r\nImportError: cannot import name FTP\r\n')

Any help?
Thank you very much!

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32: How to send files from internal flash to PC

Post by Roberthh » Mon Mar 16, 2020 2:00 pm

You do not need both ftplib.py and ftplib.mpy. And the .mpy file is most likely outdated anyhow, sine the bytecode version changed a few times in the past. But then, I cannot load ftplib.py due to memory restrictions. Loading the .mpy versions after recomppiling works.

Testing through a tool like ampy is a little bit difficult, because messages from ampy, Rpi and the targets are mixed.
Try to connect via a terminal emulator like picocom to the board and run your script from the REPL prompt. That gives you less spoiled errors.

Note: You do not have ot run boot.py and main.py manually. They are executed on every device boot anyhow.

User avatar
mkcastillote
Posts: 4
Joined: Mon Mar 16, 2020 10:35 am

Re: ESP32: How to send files from internal flash to PC

Post by mkcastillote » Mon Mar 16, 2020 2:06 pm

Thank you very much Roberthh. :)

Python Candy
Posts: 2
Joined: Mon Jul 26, 2021 6:18 am

Re: ESP32: How to send files from internal flash to PC

Post by Python Candy » Tue Jul 27, 2021 9:55 pm

I just wrote a very simple tool to fetch files from a MicroPython board (I am using a Raspi pico), you can grab it from here:
https://github.com/udi-hakim/Tools

modulusmath
Posts: 30
Joined: Thu Jun 30, 2022 3:21 am

Re: ESP32: How to send files from internal flash to PC

Post by modulusmath » Tue Jul 12, 2022 5:34 pm

If you use Thonny and keep the files on the esp32 in one directory; you can download the files in batch by downloading the parent directory.

Post Reply