1

I am connecting to an SFTP server using pysftp but need to reconfigure it to go through a proxy. Since pysftp doesn't support it, I'm thinking of using Paramiko.

Looks like I'm utilizing the benefits of pysftp.Connection, since it looks like my code is using recursive file transfers.

What are the steps I would need to do to re-create pysftp.Connection but with the option to use a proxy? Looking through the codebase is a little frightening since I'm not sure what to edit...

simplycoding
  • 2,770
  • 9
  • 46
  • 91

1 Answers1

2

You can do:

import pysftp
import paramiko

hostname, prot = 'some.host.name', 22
proxy = paramiko.proxy.ProxyCommand('/usr/bin/nc --proxy proxy.foobar:8080 %s %d' % (hostname, port))
t = paramiko.Transport(sock=proxy)
t.connect(username='abc', password='123')

sftp = paramiko.SFTPClient.from_transport(t) # back to pysftp wrapper
sftp.listdir('.')

Here's the origin of the code, with some discussion.

namesys
  • 21
  • 2