-
-
Save mudphone/7a3ab5a286ff6ca7511557c87aae2bb5 to your computer and use it in GitHub Desktop.
SFTP via SOCKS Proxy using Paramiko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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