Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Combines several solutions found on the internet
- class ImplicitFTP_TLS(ftplib.FTP_TLS):
- """FTP_TLS subclass to support implicit FTPS."""
- """Constructor takes a boolean parameter ignore_PASV_host whether o ignore the hostname"""
- """in the PASV response, and use the hostname from the session instead"""
- def __init__(self, *args, **kwargs):
- self.ignore_PASV_host = kwargs.get('ignore_PASV_host') == True
- super().__init__(*args, {k: v for k, v in kwargs.items() if not k == 'ignore_PASV_host'})
- self._sock = None
- @property
- def sock(self):
- """Return the socket."""
- return self._sock
- @sock.setter
- def sock(self, value):
- """When modifying the socket, ensure that it is ssl wrapped."""
- 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):
- """Override the ntransfercmd method"""
- conn, size = ftplib.FTP.ntransfercmd(self, cmd, rest)
- conn = self.sock.context.wrap_socket(
- conn, server_hostname=self.host, session=self.sock.session
- )
- return conn, size
- def makepasv(self):
- host, port = super().makepasv()
- return (self.host if self.ignore_PASV_host else host), port
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement