remote_ls.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import paramiko
  2. import sys
  3. def run_remote_command(hostname, username, password, command):
  4. try:
  5. client = paramiko.SSHClient()
  6. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  7. client.connect(hostname, username=username, password=password)
  8. stdin, stdout, stderr = client.exec_command(command)
  9. output = stdout.read().decode()
  10. error = stderr.read().decode()
  11. client.close()
  12. return output, error
  13. except Exception as e:
  14. return None, str(e)
  15. if __name__ == "__main__":
  16. host = "192.168.130.171"
  17. user = "roni"
  18. pw = "BTSai123"
  19. cmd = "ollama --version && echo '---' && curl -s http://localhost:11434/api/version"
  20. print(f"Connecting to {host}...")
  21. out, err = run_remote_command(host, user, pw, cmd)
  22. if out is not None:
  23. with open("scratch/remote_output.txt", "w", encoding="utf-8") as f:
  24. f.write(out)
  25. print("Output written to scratch/remote_output.txt")
  26. if err:
  27. print("--- Error ---")
  28. print(err)
  29. else:
  30. print(f"SSH Error: {err}")