Telnet and running commands on remote systems
aleax at aleax.it
Thu Jan 10 03:35:11 EST 2002
"Doug Farrell" <writeson at earthlink.net> wrote in message
news:0H8%7.17963$zw3.1869916 at newsread1.prod.itd.earthlink.net...
> Hi all,
> I'm working on a program to do release work on our servers, which
> means moving files around on various machines and running commands on
> those servers (tar, mv, etc.). How could I do this in Python? Should I
> use telnetlib or popen or something else? I'm trying to use telnetlib
> right now and not having much luck sending commands to the remote
> machine and looking at the returned results. I want to have a Python
If you're running within an ENTIRELY secure and trusted local area
network, well protected against the "outside" world, telnetlib is OK.
An example of exactly the thing you're trying to do is at:
It exemplifies exactly the use of telnetlib for your purposes.
*TAKE CARE*: if you're not ready to bet your firstborn that your
LAN is *entirely* secured and solidly firewalled against the world,
you're probably best off not even installing telnet daemons on any
of your machines. OpenSSH (or other implementations of SSH) are
VASTLY more robust -- no sending of packets with in-clear passwords
and so on.
gives an example of using ssh from Python (via just an os.popen)
for a specific task. Together with ssh's ability for non-
interactive authentication (via private/public key pairs),
and commandline arguments to ssh, scp and sftp, it's often
easier to do things with ssh than with the telnet protocol,
even though Python has a module specifically supporting the
former but no specific ssh support (AFAIK).
YMMV, but, as for me, I feel much safer in having no telnet
(nor any non-anonymous FTP) taking place, and relying on SSH
and friends for everything...
More information about the Python-list