-
-
Save mudphone/fa4a9ad019a0c6c7b523fa41fe0cc45a 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