Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Paramiko SFTP username/password authentication via SOCKS proxy
import paramiko
import socket
import socks
# set up SOCKS proxy
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy_details['host'],
proxy_details['port'], True, proxy_details['username'],
proxy_details['password'])
socket.socket = socks.socksocket
# initialize paramiko ssh client
transport = paramiko.SSHClient()
# ignore missing host key as we rely on username/password auth
transport.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# connect() automatically uses the SOCKS proxy socket
transport.connect(auth_credentials['host'], username = auth_credentials['user_name'],
password = auth_credentials['password'])
# start SFTP Client from SSH transport
sftp = paramiko.SFTPClient.from_transport(transport.get_transport())
# do stuff
# cleanup
sftp.close()
transport.close()
@juliuscrn

This comment has been minimized.

Copy link

@juliuscrn juliuscrn commented Jun 27, 2017

Does it still work for you? I use python 3 and I get the following error:
GeneralProxyError: Socket error: SOCKS5 proxy server sent invalid data

@goinnn

This comment has been minimized.

Copy link

@goinnn goinnn commented Mar 30, 2020

Currently, at least, with Python 3.6 works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment