How to use the pysftp.exceptions 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 Catboy96 / Gekko / gekko / gekko.py View on Github external
while '' in lines:
                lines.remove('')
    except FileNotFoundError:
        lines = []

    # Establish SFTP connection
    try:
        cnopts = pysftp.CnOpts()
        cnopts.hostkeys = None
        print("Connecting to %s:%s... " % (host, port), end='')
        if key != '':
            sftp = pysftp.Connection(host, username=user, port=int(port), private_key=key, cnopts=cnopts)
        else:
            sftp = pysftp.Connection(host, username=user, port=int(port), password=password, cnopts=cnopts)
        print("Connected.")
    except pysftp.exceptions.ConnectionException:
        print("\n\nAn error occurred when establishing connection.\nCheck for Internet connection.")
        exit(8)
    except paramiko.ssh_exception.AuthenticationException:
        print("\n\nAuthentication failed.")
        exit(7)

    # Check for uploading directory
    print("Checking for %s... " % path, end='')
    if sftp.exists(path):
        print("Exist.")
        print("Change directory to %s... Done." % path)
        sftp.cd(path)
    else:
        # Remote directory do not exist
        # Print every file not marked as 'ignored'
        total_size = 0