Wrapping SSH requires handling a lot of different exceptions. If you want to avoid bugs and errors, find someone else's library for handling SSH that deals with things like host key prompts, changed fingerprints, filesystem permissions, connection errors and reconnects. If you're running commands, some may need things like proper PTY handling.