Search code examples
pythonauthenticationruntime-errorsftpparamiko

Paramiko authentication failed / authentication exception


I'm using python paramiko, to connect to an SFTP portal. But, every time I run this code it fails with this error

paramiko.ssh_exception.AuthenticationException: Authentication failed.

This is the code I'm using:

import paramiko

host = 'https://sftp-portal.com'
port = 1022
username = 'username'
password = 'password!'

transport = paramiko.Transport((host,port))
transport.connect(None,username,password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.get('/files/csv/example.csv', '/Users/User/Desktop')
sftp.close()

What am I doing wrong? any help with this is highly appreciated.


Solution

  • The "host" part of the tuple you pass to the Transport constructor is a "hostname", not a "URL":

    host = 'sftp-portal.com'