Asked  7 Months ago    Answers:  5   Viewed   42 times

I'm trying to get started with the Paramiko library, but the library is throwing an exception as soon as I try to connect with the following simple program:

import paramiko
ssh = paramiko.SSHClient()
ssh.connect('', username='boatzart', password='mypassword')

The error I get is:

Traceback (most recent call last):
File "", line 6, in <module>
File "build/bdist.macosx-10.7-intel/egg/paramiko/", line 316, in connect
File "build/bdist.macosx-10.7-intel/egg/paramiko/", line 85, in missing_host_key
paramiko.SSHException: Unknown server

This occurs no matter which server I try.



The exception was raised because you are missing a host key, the rather cryptic "Unknown server" is the clue - since the exception was raised from missing_host_key

Try this instead:

import paramiko

paramiko.util.log_to_file('ssh.log') # sets up logging

client = paramiko.SSHClient()
client.connect('', username=username, password=password)
stdin, stdout, stderr = client.exec_command('ls -l')
Tuesday, June 1, 2021
answered 7 Months ago

Paramiko by default verifies a size of the uploaded file after the upload.

If the file is moved away immediately after upload, the check fails.

To avoid the check, set confirm parameter of SFTPClient.put to False.

sftp_client.put(localpath, remotepath, confirm=False)

I believe the check is redundant anyway, see
How to perform checksums during a SFTP file transfer for data integrity?

For a similar question about pysftp (what is a wrapper around Paramiko), see:
Python pysftp.put raises "No such file" exception although file is uploaded

Friday, July 30, 2021
answered 4 Months ago

You're on the right track with your second example, but it isn't quite formatted right. You're actually getting a 2 character string there.

SSH.send("x03") should do the trick.

However, I'd probably have used this instead.


Friday, August 6, 2021
Justin Charles
answered 4 Months ago

Should have used as and rather I used sshout only while printing.

Tuesday, August 17, 2021
answered 4 Months ago

So this question has been up for almost 24 hours on 3 different websites and not one true answer was givin related to this. I am kind of shocked. I tried running the script as a subprocess and then piping the output to stdout. It worked:

import subprocess
proc = subprocess.Popen(['python',''],stdout=subprocess.PIPE)
for line in iter(proc.stdout.readline, ''):
        print line

I can now control the output for every line printed proc.stdout.readline.

Such a simple answer really.

Wednesday, August 25, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :