0

I was trying to make a connection to a Free Public SFTP Server that I found here using pysftp.

I tried:

import pysftp

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None 


sftp = pysftp.Connection('demo.wftpserver.com:2222', username='demo-user', password='demo-user', cnopts=cnopts)
sftp.close()

However it yields:

ConnectionException: ('demo.wftpserver.com:2222', 22) and gaierror: [Errno -2] Name or service not known

Is this a workaround to this issue?

Please Advise.

The Singularity
  • 2,428
  • 3
  • 19
  • 48

1 Answers1

1

The port number goes to the port parameter of Connection constructor. The host parameter takes just a hostname.

sftp = pysftp.Connection(
    'demo.wftpserver.com', port=2222, username='demo-user', password='demo-user',
    cnopts=cnopts)

Obligatory warning: Do not set cnopts.hostkeys = None, unless you do not care about security. For the correct solution see Verify host key with pysftp.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992