Discussion:
Paramiko SSHClient
Petrucci Andreas
2009-12-04 05:15:16 UTC
Permalink
Hi everyone, i just joined the list and being newbie I have 2 questions.

1) I am running a never ending script that every 5 seconds make a SSH connection to different hosts. All work (almost) excellent but sometimes the script stops showing me this error :

No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
File "myfile.py", line 156, in <module>
client.connect(node, username='MYUSERNAME', password='MYPASSWORD', key_filename='.../key',timeout=50)
File "/usr/lib/pymodules/python2.6/paramiko/client.py", line 288, in connect
t.start_client()
File "/usr/lib/pymodules/python2.6/paramiko/transport.py", line 440, in start_client
raise e
paramiko.SSHException: Error reading SSH protocol banner

The crucial code is below:


client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(node, username='MYUSERNAME', password='MYPASSWORD', key_filename='.../key',timeout=50)
except paramiko.SSHException, socket.error :
print "connect error"
continue

Any ideas?

2)I have established a SSH connection with a remote host, can I transfer a file from this host to me without opening a new connection from the remote host to me? Is there a way doing this with paramiko?

Thanks in advance,
Andreas




_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
james bardin
2009-12-04 15:28:50 UTC
Permalink
2009/12/4 Petrucci Andreas <***@hotmail.com>:
> Hi everyone, i just joined the list and being newbie I have 2 questions.
>
> 1) I am running a never ending script that every 5 seconds make a SSH
> connection to different hosts. All work (almost) excellent but sometimes the
> script stops showing me this error :
...
>                      paramiko.SSHException: Error reading SSH protocol
> banner

You're connecting to a host that isn't sending an SSH protocol banner.
That host, or at least it's sshd, is probably hung.


> Any ideas?
>
> 2)I have established a SSH connection with a remote host, can I transfer a
> file from this host to me without opening a new connection from the remote
> host to me? Is there a way doing this with paramiko?
>

Yes, using sftp. Look into the SFTPClient class.


-jim
james bardin
2009-12-04 20:14:08 UTC
Permalink
2009/12/4 Petrucci Andreas <***@hotmail.com>
>
> A quite strange thing is that with this specific host most of the time the connection is established successfully but sometimes the above SSHException occurs.
> From my perspective, it's not up to me to correct this, am I right?
>

Yes, this is the fault of the remote host, or the network itself.


>
> <class 'paramiko.SSHException'>: EOF during negotiation
>       args = ('EOF during negotiation',)
>       message = 'EOF during negotiation'
>

It looks like the server is doing something wrong, or doesn't support
the sftp subsystem.
What type of server are you connecting to?


-jim
Petrucci Andreas
2009-12-04 20:19:21 UTC
Permalink
> Date: Fri, 4 Dec 2009 15:14:08 -0500
> Subject: Re: [paramiko] Paramiko SSHClient
> From: ***@bu.edu
> To: ***@hotmail.com
> CC: ***@lag.net
>
> 2009/12/4 Petrucci Andreas <***@hotmail.com>
> >
> > A quite strange thing is that with this specific host most of the time the connection is established successfully but sometimes the above SSHException occurs.
> > From my perspective, it's not up to me to correct this, am I right?
> >
>
> Yes, this is the fault of the remote host, or the network itself.
>
>
> >
> > <class 'paramiko.SSHException'>: EOF during negotiation
> > args = ('EOF during negotiation',)
> > message = 'EOF during negotiation'
> >
>
> It looks like the server is doing something wrong, or doesn't support
> the sftp subsystem.
> What type of server are you connecting to?
>
>
> -jim


it's a PlanetLab node, and i have this problem with all PlanetLab nodes that i cope with.

_________________________________________________________________
Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009
james bardin
2009-12-04 20:34:54 UTC
Permalink
On Fri, Dec 4, 2009 at 3:19 PM, Petrucci Andreas
<***@hotmail.com> wrote:
>
>
> it's a PlanetLab node, and i have this problem with all PlanetLab nodes that
> i cope with.
>

I mean what is the ssh-server/OS?

Does other sftp clients work (like sftp from openssh)?
Petrucci Andreas
2009-12-04 21:19:00 UTC
Permalink
> Date: Fri, 4 Dec 2009 15:34:54 -0500
> Subject: Re: [paramiko] Paramiko SSHClient
> From: ***@bu.edu
> To: ***@hotmail.com
> CC: ***@lag.net
>
> On Fri, Dec 4, 2009 at 3:19 PM, Petrucci Andreas
> <***@hotmail.com> wrote:
> >
> >
> > it's a PlanetLab node, and i have this problem with all PlanetLab nodes that
> > i cope with.
> >
>
> I mean what is the ssh-server/OS?
>
> Does other sftp clients work (like sftp from openssh)?

OpenSSH_4.7p1, OpenSSL 0.9.8b 04 May 2006
Fedora release 8
2.6.22.19

I tried with filezilla and sftp but no connection was accomplished. Any alternatives?

_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
james bardin
2009-12-04 21:39:56 UTC
Permalink
On Fri, Dec 4, 2009 at 4:19 PM, Petrucci Andreas
<***@hotmail.com> wrote:

>
> OpenSSH_4.7p1, OpenSSL 0.9.8b 04 May 2006
> Fedora release 8
> 2.6.22.19
>

You may not have any control over this, but Fedora 8 has been out of
support for a year now.

> I tried with filezilla and sftp but no connection was accomplished. Any
> alternatives?
>

If that's the case, then the server is probably not configured to
allow sftp, or is misconfigured in some way.

If the scp binary is available on the server, you could use that.
Paramiko doesn't have an scp module included, but I've posted my
implementation to the list before:
http://www.lag.net/pipermail/paramiko/2009-December/001189.html

-jim
Petrucci Andreas
2009-12-04 22:38:01 UTC
Permalink
> Date: Fri, 4 Dec 2009 16:39:56 -0500
> Subject: Re: [paramiko] Paramiko SSHClient
> From: ***@bu.edu
> To: ***@hotmail.com
> CC: ***@lag.net
>
> On Fri, Dec 4, 2009 at 4:19 PM, Petrucci Andreas
> <***@hotmail.com> wrote:
>
> >
> > OpenSSH_4.7p1, OpenSSL 0.9.8b 04 May 2006
> > Fedora release 8
> > 2.6.22.19
> >
>
> You may not have any control over this, but Fedora 8 has been out of
> support for a year now.
>
> > I tried with filezilla and sftp but no connection was accomplished. Any
> > alternatives?
> >
>
> If that's the case, then the server is probably not configured to
> allow sftp, or is misconfigured in some way.
>
> If the scp binary is available on the server, you could use that.
> Paramiko doesn't have an scp module included, but I've posted my
> implementation to the list before:
> http://www.lag.net/pipermail/paramiko/2009-December/001189.html
>
> -jim

Oh jim how i love ya! :)
it works perfectly
Thanks again for all

_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
Petrucci Andreas
2009-12-04 19:53:25 UTC
Permalink
> Date: Fri, 4 Dec 2009 10:28:50 -0500
> Subject: Re: [paramiko] Paramiko SSHClient
> From: ***@bu.edu
> To: ***@hotmail.com
> CC: ***@lag.net
>
> 2009/12/4 Petrucci Andreas <***@hotmail.com>:
> > Hi everyone, i just joined the list and being newbie I have 2 questions.
> >
> > 1) I am running a never ending script that every 5 seconds make a SSH
> > connection to different hosts. All work (almost) excellent but sometimes the
> > script stops showing me this error :
> ...
> > paramiko.SSHException: Error reading SSH protocol
> > banner
>
> You're connecting to a host that isn't sending an SSH protocol banner.
> That host, or at least it's sshd, is probably hung.
>
>
> > Any ideas?




A quite strange thing is that with this specific host most of the time
the connection is established successfully but sometimes the above
SSHException occurs.

>From my perspective, it's not up to me to correct this, am I right?



> >
> > 2)I have established a SSH connection with a remote host, can I transfer a
> > file from this host to me without opening a new connection from the remote
> > host to me? Is there a way doing this with paramiko?
> >
>
> Yes, using sftp. Look into the SFTPClient class.
>
>
> -jim



Ok, i looked the SFTPClient class but something occured ...once again.



client = paramiko.SSHClient()

client.load_system_host_keys()

client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client.connect(node, username='MYUSERNAME', password='MYPASSWORD', key_filename='.../key',timeout=50)

#until here all excellent, but...

sftpclient = client.open_sftp()

sftpclient.close()





the output is this:





313 sftpclient = client.open_sftp()


314 #except paramiko.SSHException, socket.error :


315 # print ('SSHException error')


sftpclient undefined, client = <paramiko.SSHClient object at 0x968becc>, client.open_sftp = <bound method SSHClient.open_sftp of <paramiko.SSHClient object at 0x968becc>>




/usr/lib/pymodules/python2.6/paramiko/client.py in open_sftp(self=<paramiko.SSHClient object at 0x968becc>)
376 @rtype: L{SFTPClient}


377 """


378 return self._transport.open_sftp_client()


379


380 def get_transport(self):


self = <paramiko.SSHClient object at 0x968becc>, self._transport = <paramiko.Transport at 0x969020cL (cipher aes128-cbc, 128 bits) (active; 0 open channel(s))>, self._transport.open_sftp_client = <bound method Transport.open_sftp_client of <par...s128-cbc, 128 bits) (active; 0 open channel(s))>>




/usr/lib/pymodules/python2.6/paramiko/transport.py in open_sftp_client(self=<paramiko.Transport at 0x969020cL (cipher aes128-cbc, 128 bits) (active; 0 open channel(s))>)
807 @rtype: L{SFTPClient}


808 """


809 return SFTPClient.from_transport(self)


810


811 def send_ignore(self, bytes=None):


global SFTPClient = <class 'paramiko.SFTPClient'>, SFTPClient.from_transport = <bound method type.from_transport of <class 'paramiko.SFTPClient'>>, self = <paramiko.Transport at 0x969020cL (cipher aes128-cbc, 128 bits) (active; 0 open channel(s))>




/usr/lib/pymodules/python2.6/paramiko/sftp_client.py in from_transport(cls=<class
'paramiko.SFTPClient'>, t=<paramiko.Transport at 0x969020cL
(cipher aes128-cbc, 128 bits) (active; 0 open channel(s))>)
103 return None


104 chan.invoke_subsystem('sftp')


105 return cls(chan)


106 from_transport = classmethod(from_transport)


107


cls = <class 'paramiko.SFTPClient'>, chan = <paramiko.Channel 3 (closed) -> <paramiko.Transp...s128-cbc, 128 bits) (active; 0 open channel(s))>>




/usr/lib/pymodules/python2.6/paramiko/sftp_client.py in __init__(self=<paramiko.SFTPClient
object at 0x9693a4c>, sock=<paramiko.Channel 3 (closed) ->
<paramiko.Transp...s128-cbc, 128 bits) (active; 0 open
channel(s))>>)
86 server_version = self._send_version()


87 except EOFError, x:


88 raise SSHException('EOF during negotiation')


89 self._log(INFO, 'Opened sftp connection (server version %d)' % server_version)


90


global SSHException = <class 'paramiko.SSHException'>

<class 'paramiko.SSHException'>: EOF during negotiation


args =
('EOF during negotiation',)


message =
'EOF during negotiation'










Jim thanks in advance,

Andreas

_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
Loading...