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() |
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.
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