How to use the pysftp.helpers function in pysftp

To help you get started, we’ve selected a few pysftp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AwesomeFoodCoops / odoo-production / extra_addons / auto_backup / models / db_backup.py View on Github external
params['cnopts'] = cnopts

        # If it's the first time we connect to this host
        # disable hostkey validation, and add to known_hosts
        hostkeys = None
        if cnopts.hostkeys.lookup(self.sftp_host) is None:
            hostkeys = cnopts.hostkeys
            cnopts.hostkeys = None

        sftp = pysftp.Connection(**params)
        if sftp and hostkeys is not None:
            hostkeys.add(
                self.sftp_host,
                sftp.remote_server_key.get_name(),
                sftp.remote_server_key)
            known_hosts = pysftp.helpers.known_hosts()
            if not os.path.exists(os.path.dirname(known_hosts)):
                os.makedirs(os.path.dirname(known_hosts))
            hostkeys.save(known_hosts)
            _logger.info(
                'Permanently added "%s" (%s) to the list of '
                'known hosts' % (
                    self.sftp_host,
                    sftp.remote_server_key.get_name()))
        return sftp