Implicit FTPS to ShareFile fails with "operation timed out" in Python

Solution 1:

sometimes the help you need is your own.

In order to fix this without directly modifying ftplib code (which requires jumping through hoops on a Mac because you cannot easily write/modify files in your /System/Library) I overrode the storbinary method in ftplib.FTP_TLS. That's essentially using this fix for supporting implicit FTPS:

Python FTP implicit TLS connection issue

and then adding these lines to the class tyFTP, and commenting out the conn.unwrap() call, and replacing it with 'pass':

  def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
    self.voidcmd('TYPE I')
    conn = self.transfercmd(cmd, rest)
    try:
      while 1:
        buf = fp.read(blocksize)
        if not buf: break
        conn.sendall(buf)
        if callback: callback(buf)
      if isinstance(conn, ssl.SSLSocket):
        pass
#         conn.unwrap()
    finally:
      conn.close()
    return self.voidresp()