paramiko

Guilherme Polo ggpolo at gmail.com
Wed Jan 16 14:56:06 EST 2008


2008/1/16, Tarun Kapoor <tarun.kap at gmail.com>:
> On Jan 16, 12:22 pm, "Guilherme Polo" <ggp... at gmail.com> wrote:
> > 2008/1/16, Tarun Kapoor <tarun.... at gmail.com>:
> >
> >
> >
> > > On Jan 16, 11:38 am, "Guilherme Polo" <ggp... at gmail.com> wrote:
> > > > 2008/1/16, Tarun Kapoor <tarun.... at gmail.com>:
> >
> > > > >     # now, connect and use paramiko Transport to negotiate SSH2 across
> > > > > the connection
> > > > >     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > > > >     sock.connect((hostname, port))
> >
> > > > >     t = paramiko.Transport(sock)
> > > > >     t.start_client()
> > > > >     key = t.get_remote_server_key()
> >
> > > > >     event = threading.Event()
> > > > >     t.auth_password(username=username, password=password, event=event)
> > > > >     event.wait()
> >
> > > > >     if not t.is_authenticated():
> > > > >         print "not authenticated"
> >
> > > > > output:
> > > > > not authenticated
> >
> > > > This is a different problem I guess, now you are usin get_remote_server_key.
> > > > And why are you creating event after calling start_client without
> > > > specifying it ?
> >
> > > > > On Jan 16, 11:11 am, "Guilherme Polo" <ggp... at gmail.com> wrote:
> > > > > > 2008/1/16, Tarun Kapoor <tkap... at wscm.net>:
> >
> > > > > > > I am using paramiko to do an SFTP file transfer... I was able to connect to
> > > > > > > the remote server using an SFTP client I have just to make sure that
> > > > > > > username and password are working.. This is the code.
> >
> > > > > > >     # now, connect and use paramiko Transport to negotiate SSH2 across the
> > > > > > > connection
> >
> > > > > > >     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> >
> > > > > > >     sock.connect((hostname, port))
> >
> > > > > > >     t = paramiko.Transport(sock)
> >
> > > > > > >     event = threading.Event()
> >
> > > > > > >     t.start_client(event)
> >
> > > > > > >     event.wait(15)
> >
> > > > > > >     if not t.is_active():
> >
> > > > > > >         print 'SSH negotiation failed.'
> >
> > > > > > >         sys.exit(1)
> >
> > > > > > >     else:
> >
> > > > > > >         print "SSH negotiation sucessful"
> >
> > > > > > >     event.clear()
> >
> > > > > > >     t.auth_password(username=username, password=password,event=event)
> >
> > > > > > >     if not t.is_authenticated():
> >
> > > > > > >         print "not authenticated"
> >
> > > > > > > output:
> >
> > > > > > > SSH negotiation successful
> >
> > > > > > > not authenticated
> >
> > > > > > > Tarun
> >
> > > > > > > Waterstone Capital Management
> >
> > > > > > > 2 Carlson Parkway, Suite 260
> >
> > > > > > > Plymouth, MN 55447
> >
> > > > > > > Direct: 952-697-4123
> >
> > > > > > > Cell:    612-205-2587
> > > > > > >  Disclaimer This e-mail and any attachments is confidential and intended
> > > > > > > solely for the use of the individual(s) to whom it is addressed. Any views
> > > > > > > or opinions presented are solely those of the author and do not necessarily
> > > > > > > represent those of Waterstone Capital Management, L.P and affiliates. If you
> > > > > > > are not the intended recipient, be advised that you have received this
> > > > > > > e-mail in error and that any use, dissemination, printing, forwarding or
> > > > > > > copying of this email is strictly prohibited. Please contact the sender if
> > > > > > > you have received this e-mail in error. You should also be aware that
> > > > > > > e-mails are susceptible to interference and you should not assume that the
> > > > > > > contents of this e-mail originated from the sender above or that they have
> > > > > > > been accurately reproduced in their original form. Waterstone Capital
> > > > > > > Management, L.P. and affiliates accepts no responsibility for information,
> > > > > > > or errors or omissions in this e-mail or use or misuse thereof. If in doubt,
> > > > > > > please verify the authenticity with the sender.
> > > > > > > --
> > > > > > >http://mail.python.org/mailman/listinfo/python-list
> >
> > > > > > You are missing an event.wait() after t.auth_password.
> > > > > > Also, why are you passing this magic value "15" to event.wait() ? That
> > > > > > parameter is passed to class _Verbose to indicate if debug messages
> > > > > > should be displayed or not, so typical values would be 0/1 or
> > > > > > False/True.
> >
> > > > > > --
> > > > > > -- Guilherme H. Polo Goncalves
> >
> > > > > --
> > > > >http://mail.python.org/mailman/listinfo/python-list
> >
> > > > --
> > > > -- Guilherme H. Polo Goncalves
> >
> > > ok here is the problem... I don't know what is the correct way... The
> > > only demos i have from the paramiko library use a hostkeyfile. since i
> > > don't have that i thought i would use the get_remote_key to get the
> > > key and then connect it using the code in the demo.. But clearly
> > > nothing is working...I should not HAVE to use the key since i should
> > > be able to authenticate using the password...
> >
> > > Can you please suggest the right way to go ?
> >
> > You don't need to use key to authenticate using username and password,
> > indeed. And you don't. Your first email was almost correct, you just
> > needed to add event.wait() after t.auth_password. It worked here after
> > doing that change. You can check out my version:
> >
> > import sys
> > import socket
> > import paramiko
> > import threading
> >
> > if len(sys.argv) != 4:
> >     print "%s hostname user password" % sys.argv[0]
> >     sys.exit(1)
> >
> > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > sock.connect((sys.argv[1], 22))
> >
> > t = paramiko.Transport(sock)
> > event = threading.Event()
> > t.start_client(event)
> >
> > event.wait()
> >
> > if not t.is_active():
> >     print 'SSH negotiation failed.'
> >     sys.exit(1)
> > else:
> >     print "SSH negotiation sucessful"
> >
> > event.clear()
> > t.auth_password(username=sys.argv[2], password=sys.argv[3], event=event)
> > event.wait()
> > if not t.is_authenticated():
> >     print "Authentication failed."
> > else:
> >     print "Authenticated!"
> >
> > t.close()
> >
> >
> >
> > > Thanks for your time !
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
> >
> > --
> > -- Guilherme H. Polo Goncalves
>
> ok i tried the exact same code and here is the output
> SSH negotiation sucessful
> Authentication failed.
>
>
> I am positive that the username and paddword are correct. !

I believe paramiko supports only ssh2, so be sure to check if your
server is not running ssh1.

> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves



More information about the Python-list mailing list