Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SSH Connection with Python

621 views
Skip to first unread message

Schneider

unread,
Oct 25, 2012, 6:16:58 AM10/25/12
to pytho...@python.org
Hi Folkz,
how can i create a SSH-Connection with python? I have to send some
commands to the remote host and parse their answers.
greatz Johannes

Laszlo Nagy

unread,
Oct 25, 2012, 6:34:37 AM10/25/12
to pytho...@python.org
http://www.lag.net/paramiko/

Another solution would be to use subprocess and/or pexpect


Roy Smith

unread,
Oct 25, 2012, 8:18:47 AM10/25/12
to
In article <mailman.2834.1351161...@python.org>,
At a low level, you want to look at the paramiko library. Built on top
of that, and adding hoards of neat functionality, is fabric. One of
these is likely to be what you're looking for.

http://www.lag.net/paramiko/

https://github.com/fabric/fabric

Demian Brecht

unread,
Oct 25, 2012, 9:54:43 AM10/25/12
to Schneider, pytho...@python.org

On 2012-10-25, at 3:16 AM, Schneider <j...@globe.de> wrote:

> how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers.


I have yet to use it, but Fabric (http://docs.fabfile.org/en/1.4.3/) should have everything you're looking for. I've heard nothing but good things about it.

Demian Brecht
@demianbrecht
http://demianbrecht.github.com




Peter Pearson

unread,
Oct 25, 2012, 12:55:46 PM10/25/12
to
I've been using Twisted (twistedmatrix.com). It is especially
convenient for the server end. Its organization is "event-driven",
which you may or may not find convenient.

--
To email me, substitute nowhere->spamcop, invalid->net.

Peter Pearson

unread,
Oct 25, 2012, 7:08:27 PM10/25/12
to
On 25 Oct 2012 16:55:46 GMT, Peter Pearson <ppea...@nowhere.invalid> wrote:
> On Thu, 25 Oct 2012 12:16:58 +0200, Schneider <j...@globe.de> wrote:
>> how can i create a SSH-Connection with python? I have to send some
>> commands to the remote host and parse their answers.
>> greatz Johannes
>
> I've been using Twisted (twistedmatrix.com). It is especially
> convenient for the server end. Its organization is "event-driven",
> which you may or may not find convenient.

Oops! The question was about SSH, and I was blathering about SSL.
Sorry.

Jason Friedman

unread,
Oct 25, 2012, 11:22:41 PM10/25/12
to Schneider, pytho...@python.org
> how can i create a SSH-Connection with python? I have to send some commands
> to the remote host and parse their answers.

Consider also the sh module:
http://amoffat.github.com/sh/tutorials/2-interacting_with_processes.html.

Rodrick Brown

unread,
Oct 26, 2012, 12:20:13 AM10/26/12
to Schneider, pytho...@python.org
On Oct 25, 2012, at 6:34 AM, Schneider <j...@globe.de> wrote:

> Hi Folkz,
> how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers.
> greatz Johannes

Fabric is the way to go!

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

Gelonida N

unread,
Oct 26, 2012, 7:39:36 PM10/26/12
to pytho...@python.org, pytho...@python.org
On 10/25/2012 12:47 PM, Kamlesh Mutha wrote:
> You can use paramiko module. Very easy to use.
>
>
>
I also use paramiko for a small script.

However I'm a little hesitant to use paramik for new code.

The web page says: "last updated 21-May-2011"

and the github url http://github.com/robey/paramiko/
yields me a 404

However I didn't really find any alternative.
For cross platform scripts (Linux / windows)
subprocess is not such a good alternative.


Another problem is, that paramiko depends on pycrypto 2.1+
which doesn't exist as binary release for python 2.7


Is fabric capable of performing scp / sftp

Is there any other library as alternative?

Roy Smith

unread,
Oct 26, 2012, 8:21:48 PM10/26/12
to
In article <mailman.2915.1351294...@python.org>,
Gelonida N <gelo...@gmail.com> wrote:

> Another problem is, that paramiko depends on pycrypto 2.1+
> which doesn't exist as binary release for python 2.7

I'm running paramiko-1.7.6 with python 2.7.3 on my Ubunto Precise box.
I'm reasonably sure all I did was "pip install paramiko".

On the other hand, it may have built it from source during the install.
Generally, I just let pip do it's magic and don't worry about the
details. If you're in an environment where you don't have the compiler
tool chain, you may be more constrained.

> Is fabric capable of performing scp / sftp

Fabric uses ssh to make connections, and it is capable of copying files.
For all intents and purposes, I'd say that means it is capable of
"performing scp / sftp" (both of which are just front-ends to the same
basic ssh protocol.

But, keep in mind that fabric depends on paramiko. If you can't get
paramiko installed, you probably can't get fabric either.

Gelonida N

unread,
Oct 27, 2012, 8:18:11 AM10/27/12
to pytho...@python.org
On 10/27/2012 02:21 AM, Roy Smith wrote:
> In article <mailman.2915.1351294...@python.org>,
> Gelonida N <gelo...@gmail.com> wrote:
>
>> Another problem is, that paramiko depends on pycrypto 2.1+
>> which doesn't exist as binary release for python 2.7
>
> I'm running paramiko-1.7.6 with python 2.7.3 on my Ubunto Precise box.
> I'm reasonably sure all I did was "pip install paramiko".

Apologies. I failed to mention, that I was talking about Windows not Linux.

I use Python for applications, that should work under Linux and under
Windows.

>
> But, keep in mind that fabric depends on paramiko. If you can't get
> paramiko installed, you probably can't get fabric either.
>
Thanks, that's good to know, so I don't have to bother looking at farbic
(at least not as solution on windows python 2.7 without having to try to
recompile pycrypto myself)


Cameron Simpson

unread,
Oct 27, 2012, 8:35:23 PM10/27/12
to Gelonida N, pytho...@python.org
Many years ago we ran an ssh executable on Windows; it was a tiny
standalone kit consisting, IIRC, of the Cygwin libc and ssh. Or you
could just install Cygwin...

That would let you use Python's subprocess module to invoke ssh and
dispatch your command.
--
Cameron Simpson <c...@zip.com.au>

There is a fine line between idiocy and genius. We aim to erase that line.

Gelonida N

unread,
Oct 28, 2012, 4:09:18 PM10/28/12
to pytho...@python.org
On all my work PCs cygwin is installed.

However when packaging something with py2exe I'd really prefer to not
have to install additional .exe / .dll files just for the ssh client.
This is why I like the idea of Paramiko. which requires the crypto .dll,
but that's it.

The only thing I'm concerned about paramiko is, that I don't see any
activity on the paramiko site and that one library it depends on is not
available is windows binary package for newer versions of python.

For the time being I stick with paramiko as I'm still on py2.6, but I
wanted to have some feedback, whether this path can easily be followed
in the mid term future or whther I ahd to fall back to a minimalist set
of ssh executables / dlls and a subprocess wrapper.



Gelonida N

unread,
Oct 28, 2012, 4:15:52 PM10/28/12
to pytho...@python.org
On 10/26/2012 05:22 AM, Jason Friedman wrote:
>> how can i create a SSH-Connection with python? I have to send some commands
>> to the remote host and parse their answers.
>
Just a minor comment: The sh module looks intersting, but it's not
supported for Windows platforms.

Please note: I'm not the original poster, so perhaps this is no issue
for him.

Schneider

unread,
Oct 29, 2012, 8:48:28 AM10/29/12
to Rodrick Brown, pytho...@python.org
thank you guys for the huge list of answers,
In my setting I have to access some routers and firewall from a
linux-client.

I think I'll try Fabric.


On 26.10.2012 06:20, Rodrick Brown wrote:
> On Oct 25, 2012, at 6:34 AM, Schneider <j...@globe.de> wrote:
>
>> Hi Folkz,
>> how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers.

Christian

unread,
Oct 29, 2012, 9:03:44 AM10/29/12
to pytho...@python.org
There is a module in chilkat.
http://www.example-code.com/python/ssh_exec.asp
Don't know if it is worth the money, never used it.

Christian

Christian

unread,
Oct 29, 2012, 9:03:44 AM10/29/12
to comp.lan...@googlegroups.com, pytho...@python.org
Am Donnerstag, 25. Oktober 2012 12:31:46 UTC+2 schrieb Schneider:

Roy Smith

unread,
Oct 29, 2012, 9:10:57 AM10/29/12
to
In article <mailman.2977.1351455...@python.org>,
Gelonida N <gelo...@gmail.com> wrote:

> The sh module looks intersting, but it's not supported for Windows
> platforms.

"The X module looks interesting but it's not supported for Windows" is
true for many values of X. It's all part of the TCO of using a
brain-dead operating system.

David Robinow

unread,
Oct 29, 2012, 11:18:38 AM10/29/12
to Gelonida N, pytho...@python.org
On Sun, Oct 28, 2012 at 4:09 PM, Gelonida N <gelo...@gmail.com> wrote:
> The only thing I'm concerned about paramiko is, that I don't see any
> activity on the paramiko site and that one library it depends on is not
> available is windows binary package for newer versions of python.
>
I don't understand why this is a problem.
\python27\python setup.py install #for pycrypto & paramiko
\python27\python test.py # for paramiko

Works for me. Of course, you need Visual C++ 2008, but the free
express edition is sufficient, and you should have that anyway if
you're doing Windows development. If that's too hard for you, try
http://www.serenethinking.com/bitlift/download.html
[not my site, no guarantees]

Gelonida N

unread,
Oct 29, 2012, 5:44:09 PM10/29/12
to pytho...@python.org
It's not a problem. It's an inconvenience.

We're having multiple PCs. Many of the PC owners don't want to write any
C-code and don't want to be bothered with registering at Microsoft just
to install a module and using a library.

Normally my preferred approach is, that somebody wanting to use any
library, that I wrote) can install all dependencies by:

- Installing Python
- installing easy_install (and pip)
and be able to install all the rest with easy_install

Using a library, that forces users to have to install MS-VC or mingw or
to install binaries from non-pypy sites is something I try to avoid.

My next preferred approach would be to bundle such dependencies by
myself, but this would involve to check all the legal stuff of each
library to see whether this is possible or not, etc . . .


Apart from that I consider the existence of Windows binary packages as
kind of an indicator of the health/popularity of a package and whether
it has been used sufficiently under Windows to be considered working
well under Windows.








Gelonida N

unread,
Oct 29, 2012, 5:51:19 PM10/29/12
to pytho...@python.org
If I write server side code, then I choose my server and my OS, so I
won't encounter Windows

Unfortunately most the customers won't let me choose their client
hardware / client OS.

Thus I decide to write my applications cross platform whenever possible
and try to choose libraries accordingly.






Roy Smith

unread,
Oct 29, 2012, 6:08:36 PM10/29/12
to
In article <mailman.3048.1351547...@python.org>,
Gelonida N <gelo...@gmail.com> wrote:

> On 10/29/2012 02:10 PM, Roy Smith wrote:
> > In article <mailman.2977.1351455...@python.org>,
> > Gelonida N <gelo...@gmail.com> wrote:
> >
> >> The sh module looks intersting, but it's not supported for Windows
> >> platforms.
> >
> > "The X module looks interesting but it's not supported for Windows" is
> > true for many values of X. It's all part of the TCO of using a
> > brain-dead operating system.
>
> If I write server side code, then I choose my server and my OS, so I
> won't encounter Windows
>
> Unfortunately most the customers won't let me choose their client
> hardware / client OS.
>
> Thus I decide to write my applications cross platform whenever possible
> and try to choose libraries accordingly.

The other alternative is to chose your customers better :-)
0 new messages