+ perror("FTP warning: %s %s" % (detail, path))
+
+class SFTPSync(Syncer):
+ def __init__(self, url):
+ import paramiko
+ # get host key, if we know one
+ hostkeytype = None
+ hostkey = None
+ try:
+ host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
+ except IOError:
+ try:
+ # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
+ host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
+ except IOError:
+ print '*** Unable to open host keys file'
+ host_keys = {}
+
+ if host_keys.has_key(url.hostname):
+ hostkeytype = host_keys[url.hostname].keys()[0]
+ hostkey = host_keys[url.hostname][hostkeytype]
+ print 'Using host key of type %s' % hostkeytype
+
+
+ # now, connect and use paramiko Transport to negotiate SSH2 across the connection
+ port = 22
+ if url.port: port = url.port
+ self.t = paramiko.Transport((url.hostname, port))
+ password = url.password
+ if not password: password = options.password
+ self.t.connect(username=url.username, password=password, hostkey=hostkey)
+ self.sftp = paramiko.SFTPClient.from_transport(self.t)