Guest User

Untitled

a guest
Mar 5th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. # Deberias indicar el interprete y el juego de caracteres a usar
  2. # nuevo comentario desde branch local alex
  3. import paramiko
  4. from getpass import getpass
  5.  
  6. paramiko.util.log_to_file('paramiko_1.log')
  7.  
  8. USUARIO = input('USUARIO: ')
  9. clave = getpass('clave: ')
  10. HOST = '192.168.0.10'
  11. PUERTO = 22
  12.  
  13.  
  14. datos = dict(hostname=HOST, port=PUERTO, username=USUARIO, password=clave)
  15.  
  16. def get_conection():
  17. ssh_client = paramiko.SSHClient()
  18. ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  19. ssh_client.connect(**datos)
  20. return ssh_client
  21.  
  22. def set_command(ssh_obj):
  23.  
  24. entrada, salida, error = ssh_obj.exec_command(' HOLA MUNDO-----------')
  25. print(salida.readlines())
  26.  
  27. ruta='/home/alex'
  28.  
  29. ## cliente sftp
  30. sftp = ssh_obj.open_sftp()
  31. archivos = sftp.listdir()
  32. for archivo in archivos:
  33. archivo_remoto = "%(ruta)s/%(nombre)s" % dict(ruta=ruta, nombre=archivo)
  34. print ("Descargando: %s" % archivo_remoto)
  35. try:
  36. sftp.get(archivo_remoto, "/{}".format(archivo))
  37. print ("copiado archivo {}".format(archivo))
  38. except:
  39. print ("Fallo al intentar copiar {}. Tal vez es un directorio.".format(archivo))
  40. sftp.close()
  41.  
  42. def realizar():
  43. print("inciando conexion")
  44. ssh_obj = get_conection()
  45. print("corremos el comando: echo hola")
  46. set_command(ssh_obj)
  47. print("finalizando correctament")
  48. ssh_obj.close()
  49.  
  50. if __name__ == '__main__':
  51. realizar()
Add Comment
Please, Sign In to add comment