通过python连接到SFTP服务器

时间:2020-07-02 07:02:22

标签: python server python-requests sftp pysftp

我已经待了几天了。我想知道是否有人可以帮助我提供有关如何连接到下面的sFTP服务器的任何建议。 我尝试过的python代码如下:

trigger:
- manual-tests
pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
  displayName: 'npm install'

- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run test'
  continueOnError: true

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/test-output-*.xml'
    testRunTitle: 'My Test Cases'

当那不起作用时,我尝试了此操作:

import pysftp

with pysftp.Connection(host ='https://api1.datasource.eex-group.com ', username = 'blablabla', password ='blablabla') as sftp:
    
    print ('Connected!')

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None   
with pysftp.Connection(host ='https://api1.datasource.eex-group.com ', username = 'blablabla', password ='blablabla', cnopts=cnopts) as sftp:

print ('Connected!')

这里还有一些解决此问题的方法: "No hostkey for host ***** found" when connecting to SFTP server with pysftp using private key Verify host key with pysftp "No hostkey for ... found" in pysftp code even though cnopts.hostkeys is set to None