blob: 14d2ee68b28e1e53b1a09363f50b7948828e3061 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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()
|