0

I am trying to download an file via SFTP in python, below is my code

import pysftp
try:
    with pysftp.Connection(host='sample.com',username='sample',password='password') as sftp:
        remotepath = '/APEXCAS.APPARA_CASF01GB.20211111.1915'
        localpath  = '/files/xml/APEXCAS.APPARA_CASF01GB.20211111.1915'
        sftp.put(localpath, remotepath)

except Exception as e:
    print(str(e))

It throws the below error, I am quite new to Python, kindly help or please let me know if any other simple way is available

No hostkey for host sample.com found.
Exception ignored in: <function Connection.__del__ at 0x000001B59664D4C0>
Traceback (most recent call last):
  File "C:\Users\sivap\.virtualenvs\paralel-backend-QGLHSfve\lib\site-packages\pysftp\__init__.py", line 1013, in __del__
    self.close()
  File "C:\Users\sivap\.virtualenvs\paralel-backend-QGLHSfve\lib\site-packages\pysftp\__init__.py", line 784, in close
    if self._sftp_live:
AttributeError: 'Connection' object has no attribute '_sftp_live'
massu1000
  • 177
  • 7

0 Answers0