Search code examples
pythonsftpdatabrickspysftp

Oops, unhandled type 3 ('unimplemented') error while connecting SFTP with Databricks


I'm trying to connect to SFTP from a notebook with databricks in python. My notebook looks like this:

import pysftp
import paramiko

# set parameters
host_name = 'xx.xxx.xxx.xxx' 
username = 'FTP_USERNAME' 
file_path_to_rsa_key = "/path/key_rsa" 
cnopts = pysftp.CnOpts() 
cnopts.hostkeys = None

# connect to SFTP
sftp = pysftp.Connection(host_name, username=username, private_key=file_path_to_rsa_key, cnopts=cnopts)
data = sftp.listdir()
sftp.close()

# Prints out the directories and files, line by line
for i in data:
    print(i)

I have the following error:

Oops, unhandled type 3 ('unimplemented')

when running the following block:

try:
  conn = pysftp.Connection(host_name, username=username, private_key=file_path_to_rsa_key, cnopts=cnopts)
  print("connection established successfully")
except:
  print('failed to establish connection to targeted server')

It print connection established successfully

What does it mean? What should I do? Is the issue with listdir()?


Solution

  • It seems that the issue is mostly because pysftp. I end up switching entirely to paramiko and everything is working fine. The SFTP server modified the login response and pysftp was too strict in the acceptable responses to take it without trouble. I noticed something similar when I tried to use a non-RSA private key that worked fine for ssh / sftp directly but not pysftp.

    There is also some interesting information here pysftp vs. Paramiko