Advertisement
Guest User

Paramiko connect SSH / SFHP via proxy

a guest
Feb 15th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. import paramiko, socks
  2.  
  3. # PySocks recommends using no arguments,
  4. # because it only supports the defaults anyway.
  5. sock = socks.socksocket()
  6.  
  7. host, port = '127.0.0.1', 1234
  8.  
  9. # Set up your proxy information for this socket
  10. sock.set_proxy(
  11.     proxy_type=socks.SOCKS5,
  12.     addr=host,
  13.     port=port,
  14.     username='spam',
  15.     password='eggs',
  16. )
  17.  
  18. # Connect the socket
  19. sock.connect((host, port))
  20.  
  21. # Connect an SSHClient
  22. client = paramiko.SSHClient()
  23. client.connect(host, port, 'username', 'password', sock=sock)
  24.  
  25. # Open SFTP session
  26. client.open_sftp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement