-1

I'm trying to connect via SFTP with paramiko and Python 2.7, to eventually get a file from remote server and put to my server. (Note it uses a non-standard port too)
But when I try to connect - it takes a really long time and then I get an authentication error. Have you have this issue have suggestions for fixing? I don't have a key, it just uses a username/password. I can connect with a graphical SSH program without issues, so the credentials seem correct. Here is code:

hostname = 'remotehostname.com'
username=   'AB1239'
password= ‘password’
port = 10022

import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username=username, password=password,port=port)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 380, in connect
    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
  File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 597, in _auth
    raise saved_exception
paramiko.ssh_exception.AuthenticationException: Authentication failed.


I am using:
>>> print paramiko.__version__
1.16.1

and python Python 2.7.5 (on linux)

http://docs.paramiko.org/en/2.4/api/transport.html# (these are for version 2.4, but note I'm using earlier version) http://docs.paramiko.org/en/2.4/api/client.html I also looked at this : Why does Paramiko hang if you use it while loading a module? but still having connection issues.

Kenster
  • 23,465
  • 21
  • 80
  • 106
  • 1
    I'd strongly suggest enabling DEBUG logging for `paramiko.transport` via the [Python `logging` module](https://docs.python.org/2/library/logging.html). If you aren't currently using it at all, the big-hammer approach is `logging.basicConfig(level=logging.DEBUG)` to just do debug logging for *everything*. Once you have some logs, [edit] them into the question. – Charles Duffy Jul 20 '18 at 16:00

1 Answers1

-2

I'm not quite sure if that answers your question 100 percent, but I thought better than no answer at all, especially since I'm pretty sure it can solve your problem, even though I haven't tested it in this release (no default port).

# coding: utf-8

from fabric.api import env, execute  # hosts
from fabric.network import ssh
from fabric.operations import get, run, sudo  # put

ssh.util.log_to_file("paramiko.log", 10)

env.host_string = 'remotehostname.com'
env.port = 10022

env.user = 'AB1239'
env.password = 'password'

# Attention: "rm -r" won't ask for password anymore!
env.warn_only = True

def blah():
    sudo('ls')
    get('/tmp/lolo*.xml', '/tmp', use_sudo=True)  # from remote to local
    # sudo('rm -r /tmp/what/no/')

execute(blah)
qräbnö
  • 2,722
  • 27
  • 40
  • I didn't downvote your answer (yet!) - But it's pretty obvious, why it got downvoted - You do not answer the question! And what's even worse, that you knew that yourself, when posting the "answer" already. – Martin Prikryl Jul 23 '18 at 08:17
  • Funny again. Have you tried it? Just because an answer doesn't fit the question 100% doesn't mean that the answer doesn't help. I have been using a very similar script with me for years. Whether you use paramiko directly or use Fabric is no problem thanks to pip. – qräbnö Jul 24 '18 at 21:52