In step 1, we begin as always with the standard Python preamble, referencing the modules that we’re going to make use of. In step 2, we define a custom exception handler that will run in the event of an unanticipated exception. It will print the error message and exit, which is appropriate behavior for a short-lived script like this.
In step 3, we read the command line argument using the standard library argparse functions. The only command line options present influence the connection strategy affecting variables such as the remote TCP port number and username.
In step 4, we call the custom getPass() function if it is present and defined. If you’re in an environment where you’re using passwords rather than SSH-based key authentication, ...