Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pysftp connection issue
#1
hi all,

i am trying to connect to an AWS hosted SFTP server from my Azure Databricks Notebook.

import pysftp as sftp
from base64 import decodebytes
import paramiko

keydata = b"""AAAAB3NzaC1yc2EAAAADAQABAAABAQC5EVdi40ppCS+ctFidNOUxKOkzZbKkHzWYMnM+q3qvqqiouNSWlpU/zNinxIh5mQPCZnzK67dhhJfIzIoRiZ4D9/geTEeWqOtf4LjDveGEx/WCU6sjL1IUQFFa   /1oI8SyfYKwzxLNcJ7nRBCpwrnDngLPuYEurDTdy5lx8MP6VLlLqm3nGN77YtB+vuQKBZ437uduVy6xH0abcuB6H3S26EfyQoWZBJng1jn/O2yXvNhtNpVMKueCuW4NXbJoqPAU9/U6F0YGH9w2qsXFXdfdBUljonEady0vnB2ieAnUe7q1QTJ6MX+UvrEyg/EK7xHNe4GgBWM5dfRXF56B2tbYn"""
key = paramiko.RSAKey(data=decodebytes(keydata))
cnopts = pysftp.CnOpts()
cnopts.hostkeys.add('s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com', 'ssh-rsa', key)
 
with pysftp.Connection('s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com', 'user', 'xxxx', cnopts=cnopts) as sftp:
    #with sftp.cd('/pmd-bisnode-dnb/test/'):           # temporarily chdir to allcode
         print(sftp.listdir())
         #sftp.get('Bayer_CMPELK_DEV_20210326045204_SEEDFILE_HEADER.json') 
but getting the SSH Exception error:

Error:
--------------------------------------------------------------------------- SSHException Traceback (most recent call last) <command-34066901391228> in <module> 8 cnopts.hostkeys.add('s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com', 'ssh-rsa', key) 9 ---> 10 with pysftp.Connection('s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com', 'user', 'xxx', cnopts=cnopts) as sftp: 11 #with sftp.cd('/pmd-bisnode-dnb/test/'): # temporarily chdir to allcode 12 print(sftp.listdir()) /local_disk0/.ephemeral_nfs/envs/pythonEnv-02b3e90a-fb4b-4efb-9cfe-85dc962946d6/lib/python3.8/site-packages/pysftp/__init__.py in __init__(self, host, username, private_key, password, port, private_key_pass, ciphers, log, cnopts, default_path) 138 # Begin the SSH transport. 139 self._transport = None --> 140 self._start_transport(host, port) 141 self._transport.use_compression(self._cnopts.compression) 142 self._set_authentication(password, private_key, private_key_pass) /local_disk0/.ephemeral_nfs/envs/pythonEnv-02b3e90a-fb4b-4efb-9cfe-85dc962946d6/lib/python3.8/site-packages/pysftp/__init__.py in _start_transport(self, host, port) 174 '''start the transport and set the ciphers if specified.''' 175 try: --> 176 self._transport = paramiko.Transport((host, port)) 177 # Set security ciphers if set 178 if self._cnopts.ciphers is not None: /local_disk0/.ephemeral_nfs/envs/pythonEnv-02b3e90a-fb4b-4efb-9cfe-85dc962946d6/lib/python3.8/site-packages/paramiko/transport.py in __init__(self, sock, default_window_size, default_max_packet_size, gss_kex, gss_deleg_creds, disabled_algorithms, server_sig_algs) 439 break 440 else: --> 441 raise SSHException( 442 "Unable to connect to {}: {}".format(hostname, reason) 443 ) SSHException: Unable to connect to s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com: [Errno 111] Connection refused
I have generated the keydata above using: ssh-keyscan s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com

If I don't set the "cnopts" attribute in the Connection, then i get the SSH Exception: No hostkey for host s-936a09baf53d41da9.server.transfer.eu-central-1.amazonaws.com found.

I have checked the AWS SFTP logs, but the request has not even reached there, so there is no logging information.

I am complete lost as to what am I doing wrong here.

Any help or pointer shall really be appreciated, thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Serial connection connection issue Joni_Engr 15 8,111 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  connection string issue racone 2 3,744 Feb-03-2020, 02:22 AM
Last Post: racone
  Connection issue metro17 0 3,159 Aug-23-2019, 07:32 PM
Last Post: metro17
  Does pysftp need a logout? Pedroski55 2 3,330 Jun-24-2019, 10:05 PM
Last Post: Pedroski55
  Use pysftp to get the content of a remote folder Pedroski55 0 6,922 Jun-18-2019, 09:22 AM
Last Post: Pedroski55
  pysftp pop-up 'Client forking' micksulley 5 3,342 Dec-21-2018, 02:07 AM
Last Post: Larz60+
  PySFTP ChDir Error490 whoknows 2 3,941 Jan-19-2018, 08:18 PM
Last Post: whoknows
  PYSFTP - Password Change torz 0 2,404 Dec-11-2017, 02:32 AM
Last Post: torz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020