How to use the pysftp.helpers.WTCallbacks 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 CityOfPhiladelphia / s3-sftp-sync / s3_sftp_sync / cli.py View on Github external
except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] != 'NoSuchKey':
                logger.exception('Could not fetch last modified time S3 object - {}/{}'.format(bucket, key))
                sys.exit(1)

    cnopts = pysftp.CnOpts()
    cnopts.compression = True
    cnopts.hostkeys = None

    with pysftp.Connection(config['sftp']['hostname'],
                           username=config['sftp']['username'],
                           password=config['sftp']['password'],
                           cnopts=cnopts) as sftp:

        logger.info('Walking SFTP server structure')
        wtcb = WTCallbacks()
        sftp.walktree('/', wtcb.file_cb, wtcb.dir_cb, wtcb.unk_cb)

        for fname in wtcb.flist:
            stats = sftp.sftp_client.stat(fname)

            mtime = str(stats.st_mtime)
            size = stats.st_size

            if start_time == None or mtime >= start_time:
                with sftp.sftp_client.file(fname) as file:
                    if mtime == start_time:
                        s3_hash = s3_md5(s3, bucket, key_prefix + fname)

                        # if s3 object doesn't exist, don't bother hashing sftp file
                        if s3_hash != None:
                            logger.info('{} modified time equals start_time, hash checking file'.format(fname))