Skip to content

Instantly share code, notes, and snippets.

@mudphone
Forked from ryanhiebert/socks_sftp.py
Created April 17, 2018 08:35
Show Gist options
  • Save mudphone/7a3ab5a286ff6ca7511557c87aae2bb5 to your computer and use it in GitHub Desktop.
Save mudphone/7a3ab5a286ff6ca7511557c87aae2bb5 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