Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9285723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:14:20+00:00 2026-06-18T19:14:20+00:00

I’m using the Paramiko library to run a ssh command between two servers. My

  • 0

I’m using the Paramiko library to run a ssh command between two servers.
My "Master" server is a Fedora 18 box, and my "Slave" is a Windows 7 machine. In other to run a ssh server in the Windows 7 machine, I installed FreeSSHd.After configuring freesshd I can ssh from the Fedora 18 machine into the Windows machine and execute a command like dir.
However, When I try doing so using Paramiko, I’m not having the same luck:

import paramiko
import os
import errno

"""
written by Philippe Ribeiro

class Connection
stabilishes the ssh connection between two servers
allowing the executing of commands remotely
"""
class Connection:

    def __init__( self, hostname, username, password):
        """Create a ssh client using the paramiko library
        """
        self.host = hostname
        self.user = username
        self.password = password
        self.port = 23
        self.sshclient = paramiko.SSHClient()
        self.username = username
        self.password = password

        try:        
            self.sshclient.load_system_host_keys()
            self.sshclient.set_missing_host_key_policy( paramiko.AutoAddPolicy() )

            self.sshclient.connect( hostname=self.host, port=self.port, 
                    username=self.username, password=self.password )

            self.sftpclient = self.sshclient.open_sftp()

        except SSHException, e:
            print e

        except AuthenticationException, e:
            print e

        except BadHostKeyException, e:
            print e

    def close(self):
        """Closes a client using the Connection class' API
        """
        self.sshclient.close()
        return

    def remove_directory(self, path):
        """Remove remote directory that may contain files
        It does not support directories that contain subdiretories
        """
        if self.exists(path):
            for filename in self.sftpclient.listdir(path):
                filepath = os.path.join(path, filename)
                self.sfptclient.remove(filepath)
            self.sftpclient.rmdir(path)

        return

    def exists(self, path):
        """Return True if the remote path exists
        """
        try:
            self.sfptclient.stat(path)

        except IOError, e:
            if e.errno == errno.ENOENT:
                return False
                raise
            else:
                return True

    def put_directory(self, localdir, remotedir):
        """Put a directory of files on the remote server
        Create the remote directory if it does not exist
        Does not support directories that contain subdirectories
        Return the number of files transferred
        """
        if not self.exists(remotedir):
             self.sftp.client.mkdir(remotedir)
        count = 0
        for filename in os.listdir(localdir):
             self.sftpclient.put(
                  os.path.join(localdir, filename),
                  os.path.join(remotedir, filename)
             )
             count += 1
        return count

"""
Just for testing purposes
try to connect to a Windows machine from a Unix one
so it can execute commands remotely
"""
cmd  = ["cd ..", "dir" ]
client = Connection("hostname", "username", "password")

try:
    for c in cmd:
            stdin, stdout, stderr = client.sshclient.exec_command(c)
            print stdout.readlines()

except SSHException, e:
    print e

client.close()

but when I execute:

python client.py

I get:

['Unable to execute command or shell on remote system: Failed to Execute process.\r\n']
['Unable to execute command or shell on remote system: Failed to Execute process.\r\n']

Could someone please give me a clue why isn’t working? Am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:14:22+00:00Added an answer on June 18, 2026 at 7:14 pm

    Replace cmd = ["cd ..", "dir" ] with cmd = ['cmd.exe /c "cd C:\ && dir"' ]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.