Skip to content

ftplib: FTP_TLS storbinary is hanging/never completing #103443

Description

@fmmazz

Hi,

I am trying to use ftplib.FTP_TLS to connect to a MS FTP server but whenever I try to do a storbinary it hangs the connection and only finishes it by issuing an exception.

*get* '220 Microsoft FTP Service\n'
*resp* '220 Microsoft FTP Service'
 .....
*cmd* 'STOR x.txt'
*put* 'STOR x.txt\r\n'
*get* '125 Data connection already open; Transfer starting.\n'
*resp* '125 Data connection already open; Transfer starting.'
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\ftplib.py", line 539, in storlines
    conn.unwrap()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1318, in unwrap
    s = self._sslobj.shutdown()
ConnectionResetError: [WinError 10054] An existing connection was forced to be dropped by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\ftplib.py", line 539, in storlines
    conn.unwrap()

I've seen some "solutions" on stackoverflow saying to only comment or pass the part with error on the storbinary method, such as:

   if isinstance(conn, ssl.SSLSocket):
      # HACK: Instead of attempting unwrap the connection, pass here
      pass

but this does seem like a hack and not a good solution. It would be nice to have a more definite trustworthy solution in the ftplib library.

Cheers,

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 11, 2023
  2. added a commit that references this issue on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions