Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Reuse Required Error #47

Open
jneilliii opened this issue May 7, 2023 · 1 comment
Open

Session Reuse Required Error #47

jneilliii opened this issue May 7, 2023 · 1 comment

Comments

@jneilliii
Copy link

  • Package Name: iot-ftps-client
  • Package Version: 1.1.1
  • Operating System: Windows 10 64bit
  • Python Version: 3.10

Describe the bug
Connecting to Bambu Labs X1C ftps server, which appears to be running vsFTPd 3.0.3 based on the welcome message, get an error unexpected exception occurred: 522 SSL connection failed: session reuse required when attempting to do something simple like ftps_client.list_files("/"). Trying to upload a file I get unexpected exception occurred: EOF occurred in violation of protocol (_ssl.c:2426)

To Reproduce
Steps to reproduce the behavior:

  1. Used this code to connect and attempt to list and upload file.
from iot.ftps.client import IoTFTPSClient

ftps_client = IoTFTPSClient(
    ftps_host="myServerIP",
    ftps_port=990,
    ftps_user="myServerUsername",
    ftps_pass="myServerPass***",
    ssl_implicit=True,
)

ftps_client.list_files("/")

ftps_client.upload_file("C:\\Users\\jneil\Documents\\3D Prints\\PrinterUprades\\OrdBotHadron\\OctoprintRelated\\printer-ws-client\\bambu_local\\test.3mf", "/test.3mf")

Expected behavior
To be able to list and upload files.

Screenshots
image

Additional context
I'm able to connect and list/upload files using filezilla ftp client as described in the link below without issue, so know the login information is correct.

https://forum.bambulab.com/t/we-can-now-connect-to-ftp-on-the-p1p/6464

@jneilliii
Copy link
Author

I think I may have found a fix for this use case from this stack overflow post. But applying the ntransfercmd patch seems to have broke the storbinary one. This is what I ended up with.

class ImplicitTLS(ftplib.FTP_TLS):
    """ftplib.FTP_TLS sub-class to support implicit SSL FTPS"""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._sock = None

    @property
    def sock(self):
        """return socket"""
        return self._sock

    @sock.setter
    def sock(self, value):
        """wrap and set SSL socket"""
        if value is not None and not isinstance(value, ssl.SSLSocket):
            value = self.context.wrap_socket(value)
        self._sock = value

    def ntransfercmd(self, cmd, rest=None):
        conn, size = ftplib.FTP.ntransfercmd(self, cmd, rest)
        if self._prot_p:
            conn = self.context.wrap_socket(conn,
                                            server_hostname=self.host,
                                            session=self.sock.session)  # this is the fix
        return conn, size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant