0

Using the code below I am able to connect to the transport but I receive a "Unable to open channel" error when trying to open the sftpclient. I have used this very same code to connect to one other server but I am not familiar enough with the protocol to see if there could be any server side or external factors affecting my ability to establish this connection.

   key = paramiko.RSAKey.from_private_key_file(keyfile)

   transport = paramiko.Transport((host, port))
   transport.connect(username = user, password = password, pkey = key)
   print("transport connect")

   sftp = paramiko.SFTPClient.from_transport(transport)
   print("sftp client connect")
   
   sftp.close()
   transport.close()

These are the logs:

2021-07-23 15:29:09,234 - INFO - Connected (version 2.0, client GoAnywhere6.4.3)
2021-07-23 15:29:10,130 - INFO - Auth banner: b'Welcome! Please login.\n'
2021-07-23 15:29:10,237 - INFO - Authentication continues...
2021-07-23 15:29:10,358 - WARNING - Oops, unhandled type 3 ('unimplemented')
2021-07-23 15:29:41,592 - INFO - Disconnect (code 11): Idle connection
2021-07-23 15:29:41,593 - ERROR - Unhandled Events:
Traceback (most recent call last):
  File "D:\Python Scripts\Test.py", line 57, in <module>
    sftp = paramiko.SFTPClient.from_transport(transport)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\paramiko\sftp_client.py", line 165, in from_transport
    window_size=window_size, max_packet_size=max_packet_size
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\paramiko\transport.py", line 806, in open_session
    timeout=timeout,
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\paramiko\transport.py", line 933, in open_channel
    raise e
paramiko.ssh_exception.SSHException: Unable to open channel.
user3101182
  • 138
  • 2
  • 12
  • Can connect to that SFTP server using any commandline/GUI SFTP client running on the same machine as your Python code using the same credentials? Show us its verbose log file. – Martin Prikryl Jul 23 '21 at 18:46
  • I can connect using WSFTP while using both Private Key and Password authentication it will not connect if I only select one. I have added the logs to the question. – user3101182 Jul 23 '21 at 19:32
  • Log file of the client, not Paramiko. Though Paramiko log is useful too, but we need `DEBUG` log. – Martin Prikryl Jul 24 '21 at 09:23
  • @user3101182: I am facing same issue, did you found the resolution to this issue – Raghunath Aug 26 '21 at 11:44
  • @Raghunath If you need help, start a new question and give us the information that OP here failed to provide. – Martin Prikryl Aug 26 '21 at 15:06
  • I found solution at https://stackoverflow.com/questions/28837089/multi-factor-authentication-password-and-key-with-paramiko – Raghunath Aug 27 '21 at 03:58
  • @Raghunath OK, but see my comment under the most-voted answer there – The answer is unnecessarily complicated. – Martin Prikryl Aug 27 '21 at 06:10
  • @MartinPrikryl your answer may work for single authentication i.e. either password or private key. But I need to use both password and private key. Even when connecting unix sftp command I need to use both private key and password – Raghunath Aug 27 '21 at 06:56
  • @Raghunath Just call the correct combination of `auth_password`, `auth_publickey` and `auth_interactive`. – Martin Prikryl Aug 27 '21 at 07:00
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236473/discussion-between-raghunath-and-martin-prikryl). – Raghunath Aug 27 '21 at 07:12
  • @Raghunath I've added my own answer to https://stackoverflow.com/q/28837089/850848#68949359 – if you have question, let's discuss there. – Martin Prikryl Aug 27 '21 at 07:19

0 Answers0