Skip to content

Instantly share code, notes, and snippets.

@ryanhiebert
Created December 20, 2016 18:54
Show Gist options
  • Save ryanhiebert/24ced99e48f0ddebe648160283495356 to your computer and use it in GitHub Desktop.
Save ryanhiebert/24ced99e48f0ddebe648160283495356 to your computer and use it in GitHub Desktop.
SFTP via SOCKS Proxy using Paramiko
import paramiko, socks
# PySocks recommends using no arguments,
# because it only supports the defaults anyway.
sock = socks.socksocket()
host, port = '127.0.0.1', 1234
# Set up your proxy information for this socket
sock.set_proxy(
proxy_type=socks.SOCKS5,
addr=host,
port=port,
username='spam',
password='eggs',
)
# Connect the socket
sock.connect((host, port))
# Create your Paramiko Transport
transport = paramiko.Transport(sock)
transport.connect(
username='rabbit',
password='grenade',
)
client = paramiko.SFTPClient.from_transport(transport)
# Do stuff
# Clean up
client.close()
transport.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment