1

Here is my code to connect to a Windows LAN desktop through SSH (Cygwin server is running on the LAN desktop) from my Windows PC:

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('135.24.237.178',username = 'cyg_server',password = 'sandforce')

I am able to connect successfully. But, now if I do this:

command = "cd c:\;dir"
stdin,stdout,stderr = ssh.exec_command(command)
stdout.readlines()

Then pyscripter does not output anything. Can anyone please let me know why and how I can make this code work ?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user3565150
  • 884
  • 5
  • 21
  • 49
  • Check if answer in this link works for you. http://stackoverflow.com/questions/10745138/python-paramiko-ssh – Stephen Lin Jan 19 '15 at 13:27
  • possible duplicate of [How can you get the SSH return code using Paramiko?](http://stackoverflow.com/questions/3562403/how-can-you-get-the-ssh-return-code-using-paramiko) – sunshinekitty Jan 19 '15 at 16:11

1 Answers1

1

I am unable to replicate your issue. I am using this code:

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, username = user, password = pw)
command = "cd c:\;dir"
stdin, out, err = client.exec_command(command)
print "stdout: " + out.read()

The output:

stdout: 

    Directory: C:\


Mode                LastWriteTime         Length Name                                             
----                -------------         ------ ----                                             
d-----        9/12/2016   7:34 AM                Logs                                             
d-----        9/26/2018   1:33 PM                Microsoft                                        
d-----        9/26/2018  11:47 AM                OpenSSH-Win32                                    
d-r---        9/27/2018   3:57 AM                Program Files                                    
d-----        9/26/2018  11:43 AM                Program Files (x86)                              
d-----        9/27/2018   3:56 AM                Python27                                         
d-----        9/26/2018  12:27 PM                support                                          
d-----        9/26/2018  12:27 PM                TEMP                                             
d-r---        9/27/2018   7:40 AM                Users                                            
d-----        9/27/2018   3:58 AM                Windows                                          
-a----        9/26/2018  11:42 AM            435 adrights.log                                     
-a----        9/27/2018   7:40 AM           6532 rshd.log                                         
-a----        9/26/2018  11:42 AM            107 rshdinst.log                                     
-a----        9/26/2018  11:47 AM            849 rshds.log                                        
-a----        9/26/2018  11:43 AM              0 validate.log 

I know this isn't an answer, but it wouldn't fit in the comments. The links provided in the comments don't seem to be particularly helpful either. Here is my normal code for this type of thing:

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, username = user, password = pw)
channel = client.get_transport().open_session()
command = "cd c:\;dir"
channel.exec_command(command)
out = channel.makefile().read()
err = channel.makefile_stderr().read()
returncode = channel.recv_exit_status()
channel.close()                       # channel is closed, but not the client

Hope this helps.

Zach
  • 139
  • 2
  • 10