SpotlightKid / micropython-ftplib

An FTP client library for MicroPython.
34 stars 17 forks source link

FTP_TLS error "extra keyword arguments given" on Pico W (RP2) port #18

Closed JMFUS closed 9 months ago

JMFUS commented 11 months ago

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

SpotlightKid commented 11 months ago

Please remove the wrapping of the code in a try/except block and run it again. That way you will get a full exception traceback, which shows where the error happens exactly.

JMFUS commented 11 months ago

Thx for your answer Now I have : Traceback (most recent call last): File "", line 142, in File "ftplibtls.py", line 63, in login File "ftplibtls.py", line 80, in auth TypeError: extra keyword arguments given

SpotlightKid commented 11 months ago

Which Micropython port are you using? Unix, stm32, esp2866, esp32, etc. ?

JMFUS commented 11 months ago

I'm working on a Raspberry Pi Pico W with Micropython 1.20 My FTP server is a Filezilla 0.9.60 server with this options image

SpotlightKid commented 11 months ago

The Pico W port is unfortunately not supported yet, since I don't have a Pico W board to test against.

The API of the socket and ssl modules is slightly different on each MicroPython port and it seems that the ssl.wrap_socket function on the Pico W port does not support all the keyword arguments used by the current ftplibtls code.

You can try whether the variant for the ESP boards in the esp/ftplib.py and esp/ftplibtls.py files works on the Pico W as well, but they may very well do not.

Alternatively, you can try changing lines 77-80 of ftplibtls.py to:

        wrapped = ssl.wrap_socket(sock,
                                  keyfile=self.keyfile,
                                  certfile=self.certfile)

i.e. remove the cert_reqs keyword argument.


P.S.: If someone would sponsor me by sending me a Pico W board, I could "officially" support the Pico W port :grinning:

JMFUS commented 11 months ago

I changed the lines 77-80 of the ftplibtls.py but the result is the same :(

SpotlightKid commented 11 months ago

Try removing the keyfile and certfile arguments as well.

Note: of course this means that no certificate validation will take place, which partly defeats the purpose of using TLS. So use at your own risk!

JMFUS commented 11 months ago

I allready tried to remove all argumentsand it's working I understand there's a risk

JMFUS commented 11 months ago

I can connect to my FTPS server but I can't list the files of my directory line = b'220-FileZilla Server 0.9.60 beta\r\n' line = b'220-written by Tim Kosse (tim.kosse@filezilla-project.org)\r\n' line = b'220 Please visit https://filezilla-project.org/\r\n' line = b'234 Using authentication type TLS\r\n' line = b'331 Password required for jeanmarcf\r\n' line = b'230 Logged on\r\n' line = b'200 PBSZ=0\r\n' line = b'200 Protection level set to P\r\n' line = b'200 Type set to A\r\n' line = b'227 Entering Passive Mode (88,122,12,99,128,235)\r\n' line = b'150 Opening data channel for directory listing of "/"\r\n' resp : 150 Opening data channel for directory listing of "/" sock = Traceback (most recent call last): File "", line 122, in File "ftplib.py", line 509, in retrlines File "ftplibtls.py", line 136, in ntransfercmd OSError: stream operation not supported

SpotlightKid commented 11 months ago

This seems to be another incompatibility of the socket or ssl module on the RP2.

I can only repeat: the RP2 is not supported and unless I can get my hands on a Pico W board, I can do nothing about it.

I suggest looking for help on the MicroPython forum until then:

https://forum.micropython.org/viewforum.php?f=21

JMFUS commented 11 months ago

Thx

SpotlightKid commented 9 months ago

I finally got my hands on a Raspberry Pi Pico W board and I believe this issue is now fixed and FTP over TLS also works on the rp2 port.

@JMFUS I would appreciate if you could test this and confirm that it works for you.

Please see the README for usage notes.

JMFUS commented 9 months ago

Hi Thx for the work I'm actuelly devopping other thing but when it will finished, I'll test this version and comme back to you

SpotlightKid commented 9 months ago

Assuming this to be fixed by 6c19a8446c0c0423267ecb79a949e14f05efb613.

Feel free to re-open, if the error persists with the latest version of the code in this repo.

If you have any other problems using this on the PR2 (or any other) port, please open a new ticket.