summaryrefslogtreecommitdiffhomepage
path: root/demos/demo_simple.py
diff options
context:
space:
mode:
authorRobey Pointer <robey@twitter.com>2009-07-19 15:03:45 -0700
committerRobey Pointer <robey@twitter.com>2009-07-19 15:03:45 -0700
commita0313a47e4dd978c0d0fcae2cd308239312ffea0 (patch)
tree1b125a721971fa2a396b7ac1ebaff4f75c9fb4ff /demos/demo_simple.py
parentadb349bf2b6edcaa214849901edd07d2e97b5aba (diff)
simplify the "simple" demo.
Diffstat (limited to 'demos/demo_simple.py')
-rwxr-xr-xdemos/demo_simple.py37
1 files changed, 10 insertions, 27 deletions
diff --git a/demos/demo_simple.py b/demos/demo_simple.py
index 5bcc2148..b0774bf4 100755
--- a/demos/demo_simple.py
+++ b/demos/demo_simple.py
@@ -59,43 +59,26 @@ if username == '':
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
-# get host key, if we know one
-hostkeytype = None
-hostkey = None
+# now, connect and use paramiko Client to negotiate SSH2 across the connection
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(hostname):
- hostkeytype = host_keys[hostname].keys()[0]
- hostkey = host_keys[hostname][hostkeytype]
- print 'Using host key of type %s' % hostkeytype
-
-
-# now, connect and use paramiko Transport to negotiate SSH2 across the connection
-try:
- t = paramiko.Transport((hostname, port))
- t.connect(username=username, password=password, hostkey=hostkey)
- chan = t.open_session()
- chan.get_pty()
- chan.invoke_shell()
+ client = paramiko.SSHClient()
+ client.load_system_host_keys()
+ client.set_missing_host_key_policy(paramiko.WarningPolicy)
+ print '*** Connecting...'
+ client.connect(hostname, port, username, password)
+ chan = client.invoke_shell()
+ print repr(client.get_transport())
print '*** Here we go!'
print
interactive.interactive_shell(chan)
chan.close()
- t.close()
+ client.close()
except Exception, e:
print '*** Caught exception: %s: %s' % (e.__class__, e)
traceback.print_exc()
try:
- t.close()
+ client.close()
except:
pass
sys.exit(1)