Yeah, looks like I can simplify this by using libssh2_channel_exec. I will take care of that.