I want to be able to copy a file from a remote machine using either scp, ssh or sftp in python. The best way I've found is to use ssh with sftp. I've been trying to use this example to accomplish what I need to do.
import paramiko
import os
paramiko.util.log_to_file('logfile.log')
host = "101.102.103.104"
port = 22
transport = paramiko.Transport((host, port))
password = "pass"
username = "user"
sftp = paramiko.SFTPClient.from_transport(transport)
filepath = '~/remote/file'
localpath = '~/local/file'
sftp.get(filepath, localpath)
sftp.close()
transport.close()
When I do this, I receive this error:
Traceback (most recent call last):
File "example.py", line 19, in <module>
sftp.get(filepath, localpath)
AttributeError: 'NoneType' object has no attribute 'get'
Is there something I'm missing or not doing correctly?
Thank you
sftpobject was not created