This example imports the getpass module, which will prompt the host, user, and password, establish the connection, and run some commands on a remote server.
You can find the following code in the filename: pxsshConnection.py:
import pxsshimport getpasstry: connection = pxssh.pxssh() hostname = input('hostname: ') username = input('username: ') password = getpass.getpass('password: ') connection.login (hostname, username, password) connection.sendline ('ls -l') connection.prompt() print(connection.before) connection.sendline ('df') connection.prompt() print(connection.before) connection.logout()except pxssh.ExceptionPxssh as e: print("pxssh failed on login.") print(str(e))
We can create specific methods ...