Created
June 19, 2013 21:27
-
-
Save rubanm/5818236 to your computer and use it in GitHub Desktop.
Paramiko SFTP username/password authentication via SOCKS proxy
This file contains 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 | |
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() |
Currently, at least, with Python 3.6 works
When i am using the same code i am getting error as hostname not known, Any idea on how to fix this issue
Do we need to have some code as, paramiko.client.socket.socket = socks.socksocket which is mentioned in http://vozis.blogspot.com/2015/01/python-sftp-with-paramiko-via-socks.html
And also our proxy server allows HTTP only not SOCKS can you please let me know if i need to make any changes in the above code apart from adding socks.PROXY_TYPE_HTTP in setdefaultproxy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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