This repository was archived by the owner on Sep 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparamikoTest.py
More file actions
43 lines (33 loc) · 1.29 KB
/
paramikoTest.py
File metadata and controls
43 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import paramiko
import select
import sys
# Set the hostname, username, and password for the SSH connection
hostname = 'rumad.uprm.edu'
username = 'estudiante'
password = ''
# Create a new SSH client object
client = paramiko.SSHClient()
# Automatically add the server's host key to the local HostKeys object
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the SSH server
client.connect(hostname=hostname, username=username, password=password)
# Open a channel for the SSH session
channel = client.invoke_shell()
# Set the terminal window size for the remote server
channel.resize_pty(width=200, height=50)
# Print the welcome message from the server
print(channel.recv(1024).decode())
# Enter a loop to read input from the user and output from the server
while True:
# Check if there is any input waiting from the user
if select.select([sys.stdin], [], [], 0)[0]:
# Read the input from the user and send it to the server
user_input = input()
channel.send(user_input)
# Check if there is any output waiting from the server
if select.select([channel], [], [], 0)[0]:
# Read the output from the server and print it to the console
output = channel.recv(1024).decode()
print(output)
# Close the SSH connection
client.close()