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.

Resources

Written by

Christian, Husband, Father, Programmer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store