Sorry for late reply, busy with other project.
You should investigate Shell functionality then, it looks like server that you connecting to does not allow you to execute commands directly.
When you using shell behind the scene it opens a terminal to do all operations.
What server you trying to connect to? I mean version.
In theory it also possible to issue terminal request on the channel and then execute the command but not sure if such scenario will work or supported.