How to ssh to a given machine programmatically (or with regular ssh)?

I want to talk sftp with machines I create.
I can do that using the cli, but I need the credentials to do the same from my application code