<div dir="ltr"><div>hi all i got the solution of listing all ls -l files in a listbox .</div>
<div>Next problem is to use recurrsively ls -l command again if a user selects a directory.</div>
<div>Can we use multiple in Linux commands within a program withoy using pipe.</div>
<div>i am forwarding the code.</div>
<div>i need to use ls -l command dependng on whether he chooses a directory.</div>
<div>&nbsp;</div>
<div>#!/usr/bin/env python<br>from twisted.conch.ssh import transport, userauth, connection, common, keys, channel<br>from twisted.internet import defer, protocol, reactor<br>from twisted.python import log<br>import struct, sys, getpass, os<br>
import re<br>import Tkinter<br>from Tkinter import *<br>from tkMessageBox import *<br>from os.path import exists<br>from Tkinter import *<br>import commands<br>#from DT import demo<br>import shutil<br>from os.path import exists<br>
import ftplib<br>import sys<br>from ftplib import FTP<br>from tkMessageBox import *<br>from tkFileDialog import asksaveasfilename<br>import string<br>from os import popen<br>from re import split<br>import Tkinter<br>import os</div>

<div>USER = &#39;cteam&#39;&nbsp; # replace this with a valid username<br>HOST = &#39;<a href="http://10.144.17.2">10.144.17.2</a>&#39; # and a valid host</div>
<div><br>class SimpleTransport(transport.SSHClientTransport):<br>&nbsp;&nbsp;&nbsp; def verifyHostKey(self, hostKey, fingerprint):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;host key fingerprint: %s&#39; % fingerprint<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return defer.succeed(1) </div>

<div>&nbsp;&nbsp;&nbsp; def connectionSecure(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.requestService(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleUserAuth(USER,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleConnection()))</div>
<div>class SimpleUserAuth(userauth.SSHUserAuthClient):<br>&nbsp;&nbsp;&nbsp; def getPassword(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return defer.succeed(getpass.getpass(&quot;<a href="mailto:%s@%s&#39;s">%s@%s&#39;s</a> password: &quot; % (USER, HOST)))</div>

<div>&nbsp;&nbsp;&nbsp; def getGenericAnswers(self, name, instruction, questions):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print instruction<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; answers = []<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for prompt, echo in questions:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if echo:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; answer = raw_input(prompt)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; answer = getpass.getpass(prompt)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; answers.append(answer)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return defer.succeed(answers)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def getPublicKey(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path = os.path.expanduser(&#39;~/.ssh/id_dsa&#39;) <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # this works with rsa too<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # just change the name here and in getPrivateKey<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not os.path.exists(path) or self.lastPublicKey:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # the file doesn&#39;t exist, or we&#39;ve tried a public key<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return keys.getPublicKeyString(path+&#39;.pub&#39;)</div>
<div>&nbsp;&nbsp;&nbsp; def getPrivateKey(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path = os.path.expanduser(&#39;~/.ssh/id_dsa&#39;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return defer.succeed(keys.getPrivateKeyObject(path))</div>
<div>class SimpleConnection(connection.SSHConnection):<br>&nbsp;&nbsp;&nbsp; def serviceStarted(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.openChannel(TrueChannel(2**16, 2**15, self))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.openChannel(FalseChannel(2**16, 2**15, self))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.openChannel(CatChannel(2**16, 2**15, self))</div>

<div>class TrueChannel(channel.SSHChannel):<br>&nbsp;&nbsp;&nbsp; name = &#39;session&#39; # needed for commands</div>
<div>&nbsp;&nbsp;&nbsp; def openFailed(self, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;true failed&#39;, reason<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def channelOpen(self, ignoredData):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.conn.sendRequest(self, &#39;exec&#39;, common.NS(&#39;true&#39;))</div>

<div>&nbsp;&nbsp;&nbsp; def request_exit_status(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status = struct.unpack(&#39;&gt;L&#39;, data)[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;true status was: %s&#39; % status<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.loseConnection()</div>
<div>class FalseChannel(channel.SSHChannel):<br>&nbsp;&nbsp;&nbsp; name = &#39;session&#39;</div>
<div>&nbsp;&nbsp;&nbsp; def openFailed(self, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;false failed&#39;, reason</div>
<div>&nbsp;&nbsp;&nbsp; def channelOpen(self, ignoredData):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.conn.sendRequest(self, &#39;exec&#39;, common.NS(&#39;false&#39;))</div>
<div>&nbsp;&nbsp;&nbsp; def request_exit_status(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status = struct.unpack(&#39;&gt;L&#39;, data)[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;false status was: %s&#39; % status<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.loseConnection()</div>
<div>class CatChannel(channel.SSHChannel):<br>&nbsp;&nbsp;&nbsp; name = &#39;session&#39;</div>
<div>&nbsp;&nbsp;&nbsp; def openFailed(self, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;echo failed&#39;, reason</div>
<div>&nbsp;&nbsp;&nbsp; def channelOpen(self, ignoredData):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.data = &#39;&#39;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = self.conn.sendRequest(self, &#39;exec&#39;, common.NS(&#39;ls -l&#39;), wantReply = 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d.addCallback(self._cbRequest)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<div>&nbsp;&nbsp;&nbsp; def _cbRequest(self, ignored):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.write(&#39;hello conch\n&#39;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.conn.sendEOF(self)</div>
<div>&nbsp;&nbsp;&nbsp; def dataReceived(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.data=self.data+data<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<div>&nbsp;&nbsp;&nbsp; def closed(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; win = Tkinter.Tk();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Label(win,text=&#39;CARD UPLOAD UTILITY&#39;).pack(side=TOP)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirfm = Frame(win)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirsa=Scrollbar(dirfm)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirsb= Scrollbar(dirfm)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirsb.pack(side = RIGHT, fill =Y)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirs = Listbox(dirfm,height = 50, width = 70, yscrollcommand = dirsb.set)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textsfile = Entry(dirfm)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;got data from listing: %s&#39; % self.data<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recs=self.data.split(&#39;\n&#39;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&#39;&#39;p4 = re.sub(&#39;[]&#39;&#39;&quot;&quot;[&#39;&#39;]&#39;,&#39;&#39;,&#39;%s&#39;%recs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;p4[0]&#39;,p4[0]&#39;&#39;&#39;<br>&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;shweta&#39;,recs<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var=StringVar(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for line in recs[1:]:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p4 = re.sub(&#39;[]&#39;&#39;&quot;&quot;[&#39;&#39;]&#39;,&#39;&#39;,&#39;%s&#39;%line)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print p4[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p2 = string.split(p4)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;p2&#39;,p2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p5 = []<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p5 = p5.append(p2[8])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print line<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w=p4[0] # d r _<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirs.insert(END,line)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var=StringVar(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #dirs.bind(&#39;&lt;Double-1&gt;&#39;, listd)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textsfile.pack( side = BOTTOM)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirsb.config(command=dirs.yview)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirs.pack(side=LEFT,fill=BOTH)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c=textsfile.get()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirfm.pack()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.loseConnection()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()</div>
<div>&nbsp;</div>
<div><br>protocol.ClientCreator(reactor, SimpleTransport).connectTCP(HOST, 22)</div>
<div>reactor.run()<br></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>the next problem is to execute a script from the server which accepts inputs from the user and processes it.</div>
<div>for eg sh test1.sh<br></div>
<div class="gmail_quote">On Tue, Sep 30, 2008 at 9:34 PM, Jean-Paul Calderone <span dir="ltr">&lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Tue, 30 Sep 2008 21:24:03 +0530, shweta mani &lt;<a href="mailto:shweta3230@gmail.com" target="_blank">shweta3230@gmail.com</a>&gt; wrote:<br>

<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">[snip]<br></blockquote><br>This isn&#39;t the right way to use Tk with Twisted.<br><br>See <a href="http://twistedmatrix.com/projects/core/documentation/howto/choosing-reactor.html#auto14" target="_blank">http://twistedmatrix.com/projects/core/documentation/howto/choosing-reactor.html#auto14</a><br>
<font color="#888888"><br>Jean-Paul</font> 
<div>
<div></div>
<div class="Wj3C7c"><br><br>_______________________________________________<br>Twisted-Python mailing list<br><a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br></div>