Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91569

Re: Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands

Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'calls.': 0.07; 'skip:/ 10': 0.07; 'subject:Windows': 0.09; 'cmd': 0.09; 'happens.': 0.09; 'password)': 0.09; 'question?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stderr': 0.09; 'username,': 0.09; 'python': 0.11; 'itself.': 0.11; 'def': 0.14; 'output': 0.15; 'help?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'ssh': 0.16; 'subject:between': 0.16; 'wrote:': 0.16; 'windows': 0.20; 'skip:" 30': 0.20; 'work,': 0.21; '(on': 0.22; 'module': 0.23; 'this:': 0.23; 'tried': 0.24; 'import': 0.24; 'header:User-Agent:1': 0.26; 'installed': 0.26; 'header:X-Complaints-To:1': 0.26; 'linux': 0.26; 'skip:" 20': 0.26; 'followed': 0.27; 'wonder': 0.27; 'subject: -- ': 0.27; 'command': 0.28; 'looks': 0.29; 'invoke': 0.29; 'remotely': 0.29; 'sense': 0.29; 'function': 0.30; 'connection': 0.30; 'skip:u 20': 0.30; 'work.': 0.30; 'skip:s 30': 0.31; 'code': 0.31; 'run': 0.32; 'system,': 0.32; 'username': 0.33; 'windows.': 0.33; 'server': 0.34; 'to:addr:python-list': 0.35; 'dir': 0.35; 'path': 0.35; 'replaced': 0.35; 'skip:s 60': 0.35; 'remote': 0.35; 'but': 0.36; 'subject:" ': 0.36; 'subject:: ': 0.37; 'received:org': 0.38; 'say': 0.38; 'skip:p 20': 0.38; 'someone': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'sure': 0.40; 'received:de': 0.40; 'some': 0.40; 'close': 0.61; 'below:': 0.75; 'subject:commands': 0.84; 'subject:Server': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands
Date Sun, 31 May 2015 14:18:30 +0200
Organization None
References <b92b07c3-6d2a-4fc9-a780-5803b28dadc4@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd84a6.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.242.1433074722.5151.python-list@python.org> (permalink)
Lines 57
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433074722 news.xs4all.nl 2885 [2001:888:2000:d::a6]:53602
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91569

Show key headers only | View raw


Pythonista wrote:

> Hello There:
> 
> I am using Python 2.7.6 and Paramiko module (on a Linux server) to connect
> to a Windows server and send some commands and get output. I have a
> connect function which takes IP, username and password of the remote
> Windows server and I get an sshobj when that happens. How do I use it to
> send remote calls is my question?
> 
> If it were a local system, I would just say "os.system" but not sure about
> the remote calls. Can someone help?
> 
> My code looks like below: sys.path.append("/home/me/code")
> 
> import libs.ssh_connect as ssh
> ssh_obj = ssh.new_conn(IP, username, password)
> 
> stdin, stdout, stderr = ssh_obj.exec_command("dir") #since the remote   
> system I am SSHing into is Windows.
> 
> my "new_conn" looks like this:
> 
> import paramiko
> def new_conn(IP, username, password):
>     ssh_obj = paramiko.SSHClient()
>     ssh_conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>     ssh_conn.connect(IP, username, password), timeout=30)
>     return ssh_obj
> 
>  
> if I replaced "dir" with "ipconfig" it works fine. I wonder how I can make
> "dir" work - or for that matter.. with "cd /path/to/dir"?


dir is an internal command of the windows shell. Try

ssh_obj.exec_command("cmd /c dir")

This will execute the dir command and then close the shell.

cd is also internal, but I don't think it makes sense to invoke it and then 
close the shell...


> I know for paramiko's ssh connection to work, i need cygwin installed on a
> Windows. Objective is to run commands remotely from a Linux to a Windows
> server and then process the output again on Linux server or on Windows
> itself.
> 
> I am confused because, "ipconfig" sent from Linux to Windows using
> "ssh_obj.exec_command("ipconfig")" works but not
> "ssh_obj.exec_command("dir")" - tried giving the path like "cd
> C:\Users\Administrator" for cmd or "cd C:" followed by "cd
> Users/Administrator" like in Cygwin. Neither of them work.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands Pythonista <kukki.kanchana@gmail.com> - 2015-05-31 00:02 -0700
  Re: Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands Peter Otten <__peter__@web.de> - 2015-05-31 14:18 +0200
    Re: Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands Pythonista <kukki.kanchana@gmail.com> - 2015-05-31 13:12 -0700
      Re: Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-31 20:35 -0400
        Re: Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands Pythonista <kukki.kanchana@gmail.com> - 2015-05-31 21:09 -0700

csiph-web