SFTP via SOCKS Proxy using Paramiko
I needed to use a SOCKS proxy to make an SFTP connection. The connection needed to be from a static IP address, and the connection is coming from a Heroku dyno, which doesn’t give us a static IP, so we needed to use Proximo to make it happen.
All the resources I found to do this had an annoying flaw: they monkey-patched either Paramiko or Python’s socket module. There’s no telling how badly that will end, so I dug in a little deeper.
Here’s what I came up with. It’s not quite as robust as Paramiko’s internal socket creation, but it’s working for me.