def handler(event, context): try: print('Connecting') transport = paramiko.Transport(host,port) transport.connect(username = username, pkey = mykey) sftp = paramiko.SFTPClient.from_transport(transport) print('Connected') except: print('Failed to connect') try: if sftp.listdir ==0: print("Empty directory") else: for filenames in sftp.listdir(remote_path): file_remote = str(remote_path + filenames) print(file_remote) ftp_file = sftp.file(file_remote,'r') print("Read File and start saving to s3") s3.upload_fileobj(ftp_file, Bucket='s3buckethere', Key=str(filenames)) except Exception as e: print('Failed: '+ str(e)) sftp.close() Exact Lambda error:
Connecting Connected /remotepath/testing.txt Read File and start saving to s3 Failed: unsupported operand type(s) for +: 'NoneType' and 'int' Full trace: Had to change it up a bit to get this response Response: { "errorMessage": "'<' not supported between instances of 'int' and 'NoneType'", "errorType": "TypeError", "stackTrace": [ " File "/var/task/SFTPS3.py", line 19, in handlern sftp.get(os.environ['REMOTEFILE'], LOCALFILE)n", " File "/opt/python/paramiko/sftp_client.py", line 802, in getn size = self.getfo(remotepath, fl, callback)n", " File "/opt/python/paramiko/sftp_client.py", line 780, in getfon fr.prefetch(file_size)n", " File "/opt/python/paramiko/sftp_file.py", line 471, in prefetchn while n < file_size:n" ] }
You must be logged in to post. Please login or register an account.