Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91568 > unrolled thread
| Started by | Pythonista <kukki.kanchana@gmail.com> |
|---|---|
| First post | 2015-05-31 00:02 -0700 |
| Last post | 2015-05-31 21:09 -0700 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | Pythonista <kukki.kanchana@gmail.com> |
|---|---|
| Date | 2015-05-31 00:02 -0700 |
| Subject | Python Paramiko between Linux and Windows Server -- no output obtained from Windows for "dir" or "cd" commands |
| Message-ID | <b92b07c3-6d2a-4fc9-a780-5803b28dadc4@googlegroups.com> |
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"?
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.
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-05-31 14:18 +0200 |
| Message-ID | <mailman.242.1433074722.5151.python-list@python.org> |
| In reply to | #91568 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Pythonista <kukki.kanchana@gmail.com> |
|---|---|
| Date | 2015-05-31 13:12 -0700 |
| Message-ID | <3a4707d8-46eb-4ba8-a6d9-3689b3c544f4@googlegroups.com> |
| In reply to | #91569 |
On Sunday, May 31, 2015 at 5:18:53 AM UTC-7, Peter Otten wrote:
> 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.
Thanks Peter but I got no output from your suggestion either.!
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2015-05-31 20:35 -0400 |
| Message-ID | <mailman.256.1433121594.5151.python-list@python.org> |
| In reply to | #91592 |
On Sun, 31 May 2015 13:12:24 -0700 (PDT), Pythonista
<kukki.kanchana@gmail.com> declaimed the following:
>
>Thanks Peter but I got no output from your suggestion either.!
From Windows viewpoint, I suspect EACH of the commands you send is
being executed in a totally new process, with no memory of any commands
sent previously.
As mentioned, "ipconfig" is a separate executable program file, and can
be run without being tied to a Windows command shell. "dir", "cd", "copy",
"del", and many similar functions are NOT actual programs but internal
functions of the Windows command processor.
Given the mixed quoting used in this thread I'm not sure just what was
tried or not.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Pythonista <kukki.kanchana@gmail.com> |
|---|---|
| Date | 2015-05-31 21:09 -0700 |
| Message-ID | <dafa43a5-d722-4181-af6a-af1cc46abb6e@googlegroups.com> |
| In reply to | #91606 |
On Sunday, May 31, 2015 at 6:20:19 PM UTC-7, Dennis Lee Bieber wrote: > On Sun, 31 May 2015 13:12:24 -0700 (PDT), Pythonista > <kukki.kanchana@gmail.com> declaimed the following: > > > > >Thanks Peter but I got no output from your suggestion either.! > > From Windows viewpoint, I suspect EACH of the commands you send is > being executed in a totally new process, with no memory of any commands > sent previously. > > As mentioned, "ipconfig" is a separate executable program file, and can > be run without being tied to a Windows command shell. "dir", "cd", "copy", > "del", and many similar functions are NOT actual programs but internal > functions of the Windows command processor. > > Given the mixed quoting used in this thread I'm not sure just what was > tried or not. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ Hi Peter - So I was trying "ipconfig" and "ls /path/to/dir" back to back. Apparently, I needed a sleep inbetween the two, I believe. But if "ls" was used individually, it works fine. Thanks!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web