diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/sftp.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/sftp.py b/python/sftp.py new file mode 100644 index 00000000..14d2ee68 --- /dev/null +++ b/python/sftp.py @@ -0,0 +1,19 @@ +import paramiko +import os + +hostname="alias.im" +port=22 +username="guillaume" +paramiko.util.log_to_file('sftp.log') + +t = paramiko.Transport((hostname, port)) +keys = paramiko.Agent().get_keys() +rsakeys = [key for key in keys if key.name=="ssh-rsa"] +gkey = rsakeys[0] +host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts')) +hostkey = host_keys[hostname]['ssh-rsa'] +t.connect(username="guillaume", hostkey=hostkey, pkey=gkey) +sftp = paramiko.SFTPClient.from_transport(t) +dirlist = sftp.listdir('.') +print("Dirlist:", dirlist) +t.close() |
