I am trying to upload files from C:/Test/ folder.
Code:
import pysftp
import os
host = host
port = 22
username = username
password= pass
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
try:
  conn = pysftp.Connection(host=host,port=port,username=username, password=password, cnopts=cnopts)
  print("connection established successfully")
except:
  print('failed to establish connection to targeted server')
files=os.listdir('C:/Test/')
with conn.cd('/'):
    for file in files:
            try:
                conn.put(file)
                print('uploaded file successfully: ',file)
            except:
                print('failed to upload file: ',file)
And I am getting error:
"failed to upload file" or "NoneType object has no attribute time"
But this code works fine for one file. What am I doing wrong?
This is Error:
failed to upload file:  Test.pdf
Exception ignored in: <function Connection.__del__ at 0x000001C180B71B40>
Traceback (most recent call last):
  File "C:\Python\lib\site-packages\pysftp\__init__.py", line 1013, in __del__
  File "C:\Python\lib\site-packages\pysftp\__init__.py", line 785, in close
  File "C:\Python\lib\site-packages\paramiko\sftp_client.py", line 195, in close
  File "C:\Python\lib\site-packages\paramiko\channel.py", line 671, in close
  File "C:\Python\lib\site-packages\paramiko\transport.py", line 1901, in _send_user_message
AttributeError: 'NoneType' object has no attribute 'time'