0

I'm testing how to connect an sftp through python.

import pysftp
host = 'fnord'
port = 22
username = 'fnord'
password= 'fnord'

try:
  conn = pysftp.Connection(host=host,port=port,username=username, password=password)
  print("connection established successfully")
except:
  print('failed to establish connection to targeted server')

When I try to access it through WSL, it gives me an error:

>>> try:
...   conn = pysftp.Connection(host=host,port=port,username=username, password=password)
...   print("connection established successfully")
... except:
...   print('failed to establish connection to targeted server')
... 
failed to establish connection to targeted server
Exception ignored in: <function Connection.__del__ at 0x7f0a792a03a0>
Traceback (most recent call last):
  File "/home/mocellin/fnord/venv/lib/python3.8/site-packages/pysftp/__init__.py", line 1013, in __del__
    self.close()
  File "/home/mocellin/fnord/venv/lib/python3.8/site-packages/pysftp/__init__.py", line 784, in close
    if self._sftp_live:
AttributeError: 'Connection' object has no attribute '_sftp_live'

but when I try to access it on Windows I can.

>>> try:
...   conn = pysftp.Connection(host=host,port=port,username=username, password=password)
...   print("connection established successfully")
... except:
...   print('failed to establish connection to targeted server')
... 
connection established successfully
>>> conn.close() 

I run telnet fnord 22 and it gives me.

Trying fnord ...
Connected to fnord .
Márcio Mocellin
  • 274
  • 5
  • 18

0 Answers0