spotlightkid / micropython-ftplib Goto Github PK
View Code? Open in Web Editor NEWAn FTP client library for MicroPython.
An FTP client library for MicroPython.
Hello!
I'm trying to execute the example code:
>>> from ftplibtls import FTP_TLS
>>> ftp = FTP_TLS('servername') # default port 21
>>> ftp.login('username', 'password')
>>> ftp.prot_p()
>>> ftp.retrlines('LIST')
But I'm getting this error:
Traceback (most recent call last):
File "boot.py", line 71, in
File "modules/ftplib.py", line 510, in retrlines
File "modules/ftplibtls.py", line 110, in ntransfercmd
File "modules/ftplibtls.py", line 126, in _wrap_socket
OSError: [Errno 12] ENOMEM
MicroPython v1.22.1 on 2024-01-05; Generic ESP32 module with ESP32
The connection is successful, I don't have problems with the other functions, only with dir()
, in addition to this one.
Hi,
I've got the same problem as previous person... (#2)
I can't connect to any server, debugging gives the same answer. I've tried pinging the server from my ESP32 and it works fine.
Hello! I'm using the libraries inside the folder esp
.
I want to download a file from a server with the following code:
fileToWrite = open("comoEstan.txt", "wb")
def handleDownload(block):
fileToWrite.write(block)
result = ftp.retrbinary('RETR comoEstan.txt', handleDownload)
print('ftp download comoEstan.txt return code=', result)
But I'm getting the following error:
Traceback (most recent call last):
File "", line 53, in
File "ftplib.py", line 553, in retrbinary
File "ftplib.py", line 89, in getattr
AttributeError: 'SSLSocket' object has no attribute 'recv'
Hy!
I'll try to test " ftplib.py" in my Rasp Pico W using Thonny IDE.
When I run "ftp_example.py" as is, the follow error msn appears
Testing
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "ftplib.py", line 160, in __init__
File "ftplib.py", line 217, in connect
File "ftplib.py", line 180, in _create_connection
File "ftplib.py", line 71, in _resolve_addr
OSError: -6
Can I use it on ESP32 directly? I succesfully imported it on my board, but couldn't connect to FTP server.
>> ftp = FTP(host='192.168.0.14',port=21,user='esp32',passwd='1234')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ftplib.py", line 206, in __init__
File "ftplib.py", line 264, in connect
File "ftplib.py", line 242, in _create_connection
Error: Could not connect to ('192.168.0.14', 21)
I can access to the storage via Chrome, with same settings (user, passwd, etc.)
Hi , I don't know if I am doing something wrong .
I have an esp-32 :
https://www.az-delivery.de/it/products/esp32-developmentboard
With micropython installed , and I am using Thonny .
I loaded on the esp32 , theftplib.py
file .
And then in the boot.py
file I added the line :
from ftplib import FTP
In main.py , after I connect to the wifi network , I try to access an ftp server local on the ip 192.168.1.1
the part of code dedicated to ftp in main.py is :
ftp= FTP('192.168.1.1',21,'user','password')
print('done')
When I try to run the code an error message comes up :
Could not connect to('192.168.1.1',21)
I confirm that the server is working ( i login in it with my computer) , and that the esp32 is able to ping the ip 192.168.1.1
EDIT:
Maybe i was wrong , i realized thay maybe i was using the wrong library , i have to use the library inside the esp folder right?
Hello
Here is my code :
import network
from ftplibtls import FTP_TLS
status_reseau = connect_wifi_local("NETWORK", "123456789")[1]
if status_reseau == 3:
try:
ftp_tls = FTP_TLS()
print("1")
ftp_tls.connect(adresse_serveur, port)
print("2")
ftp_tls.login(utilisateur_1, mot_de_passe_1)
print("3")
ftp_tls.prot_p()
print("4")
files = ftp_tls.nlst()
print(files)
except Exception as e:
erreur = str(e)
print("Erreur FTPS : " + str(e))
But I have the following error on the login line :
Erreur FTPS : extra keyword arguments given
Someone can help me?
Thx
Are you going to implement the FTPS or SFTP protocols?
I test the download and upload function, upload func works,but the download func have same problem, can not find the download file.
code:
result = ftp.retrbinary('RETR aaaaaa.dxf', progress)
print('ftp download aaaaaa.dxf return code=', result)
with open('README.pdf', 'rb') as fp:
result = ftp.storbinary('STOR README.pdf', fp)
print('ftp upload README.pdf return code=', result)`
serial print:
ftp download aaaaaa.dxf return code= 226 Transfer complete.
ftp upload README.pdf return code= 226 Transfer complete.
MicroPython v1.13 on 2020-09-02; ESP32 module with ESP32
Type "help()" for more information.
>>> import os
>>> os.listdir()
['README.pdf', 'esp', 'ftp.py', 'ftp_pycom.py', 'ftp_thread.py', 'ftpadvanced.py', 'ftplib.py', 'ftplibtls.py', 'main.py', 'uftpd.py']
where is the download file aaaaaa.dxf?
It seems that the parsing in test_ftplib_cmdline.py uses the same split character for password and port.
This causes specifying a user:pass to fail.
Suggest using another delimiter perhaps + between user and password
Thank you
When uploading a file larger than ~5kb, my ESP32 freezes. I tried collecting garbage to reduce memory usage, but this did not help. smaller files usually upload fine.
P.S.: If someone would sponsor me by sending me a Pico W board, I could "officially" support the Pico W port ๐
Originally posted by @SpotlightKid in #18 (comment)
It would be slightly impractical for me to ship one to you from Canada, so what level of one-off sponsorship would you need to buy one from the BerryBase link you referenced?
Thanks for making this port of ftplib available. I am having issues importing it on esp8266 though.
If I import the esp8266 port compiled to mpy
, I get the error:
>>> import ftplib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: incompatible .mpy file
If I import the esp8266 port as a py
file, I get the error:
>>> import ftplib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating %u bytes
Is there any simple fix you can think of?
I ran into 2 issues which i "fixed?" I'm new to Python so these fixes are not authoritative.
In ftplib in "def connect(self, addr):"
the code reads: self._sock.connect(_resolve_addr(addr))
but this gives an error deep in \micropython-1.19.1\py\obj.c "requested length 2 but object has length 1"
_resolve_addr(addr) returns an array with 1 element, but connect wants 2 - IP and port
the addr is already resolved.
I "fixed" by changing to: self._sock.connect(addr)
Then i encountered a python error in getmultiline at "line = line + (b'\n' + nextline)"
but line and nextline are both str, Python moans about concat a byte with a string
I "fixed" by: line = line + "\n" + nextline)
With those two changes i was able to log onto a server, list files, change dir, upload a file, quit, and close.
What is your opinion of my fixes?
thank for your project, I can download files , but I can not get file sizes, can your help me.
Traceback (most recent call last):
File "main.py", line 37, in
File "ftplib.py", line 635, in size
File "ftplib.py", line 292, in sendcmd
File "ftplib.py", line 262, in getresp
Error: 550 SIZE not allowed in ASCII mode.
code:
from ftpadvanced import AdvancedFTP
PORT = 21
ftp = AdvancedFTP('192.168.2.232', PORT)
ftp.login()
files = ftp.nlst()
print(files)
print('sizes=', ftp.size('aaaaaa.dxf'))#error
Hi there,
I'm getting the error mentioned in #2 and #4
This is my code:
from ftplib import FTP
ftp = FTP()
ftp.set_debuglevel(2)
ftp.connect('ftp1.at.proftpd.org')
I also added print('addrinfos: ', addrinfos)
before line 227 in ftplib.py
as suggested in #2 (comment)
This is what I'm getting:
addrinfos: [(2, 1, 0, '', ('86.59.114.198', 21))]
requested length 2 but object has length 1
Traceback (most recent call last):
File "<stdin>", line 44, in <module>
File "ftplib.py", line 265, in connect
File "ftplib.py", line 243, in _create_connection
Error: Could not connect to ('86.59.114.198', 21)
I was able to create a raw socket connection with this code #4 (comment), it works just fine
import usocket
IP_ADDRESS = 'ftp1.at.proftpd.org'
sock = usocket.socket()
sockaddr = usocket.getaddrinfo(IP_ADDRESS, 21)[0][-1]
sock.connect(sockaddr)
This is what I get with the code above (there's no error):
MicroPython v0.5.0-88-gb7f0c13 on 2020-05-27; Sipeed_M1 with kendryte-k210
Type "help()" for more information.
>>>
Also, I've sent messages over TCP and made HTTP requests succesfully.
# FTP server details
ftp_server = '44.241.66.173'
ftp_port = 21
ftp_user = 'dlpuser'
ftp_password = 'XXXXXX'
try:
ftp.connect(ftp_server, ftp_port, timeout=30)
ftp.set_pasv(True) # Enable passive mode
ftp.login(ftp_user, ftp_password)
print("Connected to FTP server")
except ftplib.error_perm as e_perm:
print(f"FTP Permission Error: {e_perm}")
except ftplib.error_temp as e_temp:
print(f"FTP Temporary Error: {e_temp}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
ftp.close()
Started webrepl in normal mode
An error occurred: Could not connect to ('44.241.66.173', 21)
I got this error while trying to establish an ftp connection between esp32 and the server
When I run setup.py on a new pico 2 W it gives an "ImportError: no module names 'setuptools'". I get stuck here. I am unable to find setuptools for micropython. Any assistance is appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.