-
-
Save glarrain/6b2a5300c2cce2e9ca24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Librerias necesarias | |
import paramiko | |
import os | |
# Datos para la conexion SSH | |
ssh_servidor = '10.0.70.44' | |
ssh_usuario = 'tuusuario' | |
ssh_clave = 'tucontraseña' | |
ssh_puerto = 22 | |
comando = 'ls' | |
# Conectamos al servidor | |
conexion = paramiko.Transport((ssh_servidor, ssh_puerto)) | |
conexion.connect(username = ssh_usuario, password = ssh_clave) | |
# Abrimos una sesion en el servidor | |
canal = conexion.open_session() | |
canal.exec_command(comando) | |
# Y vamos a ver la salida | |
salida = canal.makefile('rb', -1).readlines() | |
if salida: | |
for i in salida: | |
# Si ha ido todo bien mostramos el listado de directorios | |
print i | |
else: | |
# Si se ha producido algun error lo mostramos | |
print canal.makefile_stderr('rb', -1).readlines() | |
conexion.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment