Arar
Arar

Reputation: 2066

pysftp throwing OSError: General failure

I have been trying to sftp a file to remote server using pysftp library, but getting some ambiguous error OSError: General failure, it seems I was able to connect to the server, but not able to run commands like list or put.

Code:

def sftp_transfer(filename_to_transfer, ftp_server_upload_directory, sftp_config):
    print(f'file to transfer {filename_to_transfer} {sftp_config}')
    try:
        with pysftp.Connection(**sftp_config) as sftp:
            print('Connected to FTP Server successfully')
            target_fullpath = os.path.join(ftp_server_upload_directory, os.path.basename(filename_to_transfer))
            with sftp.cd(ftp_server_upload_directory):
                print('Directory Changed to the remote directory')
    except Exception as e:
        print(f'Unable to transfer the {filename_to_transfer} to {sftp_config["host"]}')
        print(Exception, e)
        raise Exception('Exception transferring file', e)
        
        
####################################################

sftp_config = {
        'host': ftp_host,
        'username': ftp_username,
        'private_key': ki,
        'cnopts': cnopts,
        'private_key_pass': '###'
    }
    return sftp_config

####################################################

def lambda_handler(event, context):
    xx = io.StringIO()
    xx.write('test \n')
    xx.seek(0)
    sftp_config = create_sftp_config()
    sftp_transfer(xx, sftp_dir, sftp_config)
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Upvotes: 1

Views: 447

Answers (1)

Arar
Arar

Reputation: 2066

After searching stackoverflow left and right, I found out that Paramiko has a bug and disabling rsa-sha2* algorithms is the way to fix it.

ssh_client.connect(
server, username=ssh_user, key_filename=ssh_keypath,
disabled_algorithms=dict(pubkeys=["rsa-sha2-512", "rsa-sha2-256"]))

Upvotes: 1

Related Questions