<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> </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 = 'cteam' # replace this with a valid username<br>HOST = '<a href="http://10.144.17.2">10.144.17.2</a>' # and a valid host</div>
<div><br>class SimpleTransport(transport.SSHClientTransport):<br> def verifyHostKey(self, hostKey, fingerprint):<br> print 'host key fingerprint: %s' % fingerprint<br> return defer.succeed(1) </div>
<div> def connectionSecure(self):<br> self.requestService(<br> SimpleUserAuth(USER,<br> SimpleConnection()))</div>
<div>class SimpleUserAuth(userauth.SSHUserAuthClient):<br> def getPassword(self):<br> return defer.succeed(getpass.getpass("<a href="mailto:%s@%s's">%s@%s's</a> password: " % (USER, HOST)))</div>
<div> def getGenericAnswers(self, name, instruction, questions):<br> print name<br> print instruction<br> answers = []<br> for prompt, echo in questions:<br> if echo:<br> answer = raw_input(prompt)<br>
else:<br> answer = getpass.getpass(prompt)<br> answers.append(answer)<br> return defer.succeed(answers)<br> <br> def getPublicKey(self):<br> path = os.path.expanduser('~/.ssh/id_dsa') <br>
# this works with rsa too<br> # just change the name here and in getPrivateKey<br> if not os.path.exists(path) or self.lastPublicKey:<br> # the file doesn't exist, or we've tried a public key<br>
return<br> return keys.getPublicKeyString(path+'.pub')</div>
<div> def getPrivateKey(self):<br> path = os.path.expanduser('~/.ssh/id_dsa')<br> return defer.succeed(keys.getPrivateKeyObject(path))</div>
<div>class SimpleConnection(connection.SSHConnection):<br> def serviceStarted(self):<br> self.openChannel(TrueChannel(2**16, 2**15, self))<br> self.openChannel(FalseChannel(2**16, 2**15, self))<br> self.openChannel(CatChannel(2**16, 2**15, self))</div>
<div>class TrueChannel(channel.SSHChannel):<br> name = 'session' # needed for commands</div>
<div> def openFailed(self, reason):<br> print 'true failed', reason<br> <br> def channelOpen(self, ignoredData):<br> self.conn.sendRequest(self, 'exec', common.NS('true'))</div>
<div> def request_exit_status(self, data):<br> status = struct.unpack('>L', data)[0]<br> print 'true status was: %s' % status<br> self.loseConnection()</div>
<div>class FalseChannel(channel.SSHChannel):<br> name = 'session'</div>
<div> def openFailed(self, reason):<br> print 'false failed', reason</div>
<div> def channelOpen(self, ignoredData):<br> self.conn.sendRequest(self, 'exec', common.NS('false'))</div>
<div> def request_exit_status(self, data):<br> status = struct.unpack('>L', data)[0]<br> print 'false status was: %s' % status<br> self.loseConnection()</div>
<div>class CatChannel(channel.SSHChannel):<br> name = 'session'</div>
<div> def openFailed(self, reason):<br> print 'echo failed', reason</div>
<div> def channelOpen(self, ignoredData):<br> self.data = ''<br> d = self.conn.sendRequest(self, 'exec', common.NS('ls -l'), wantReply = 1)<br> d.addCallback(self._cbRequest)<br>
</div>
<div> def _cbRequest(self, ignored):<br> self.write('hello conch\n')<br> self.conn.sendEOF(self)</div>
<div> def dataReceived(self, data):<br> self.data=self.data+data<br> </div>
<div> def closed(self):<br> win = Tkinter.Tk();<br> Label(win,text='CARD UPLOAD UTILITY').pack(side=TOP)<br> <br> dirfm = Frame(win)<br> dirsa=Scrollbar(dirfm)<br> dirsb= Scrollbar(dirfm)<br>
dirsb.pack(side = RIGHT, fill =Y)<br> <br> dirs = Listbox(dirfm,height = 50, width = 70, yscrollcommand = dirsb.set)<br> textsfile = Entry(dirfm)<br> print 'got data from listing: %s' % self.data<br>
recs=self.data.split('\n')<br> '''p4 = re.sub('[]''""['']','','%s'%recs)<br> print 'p4[0]',p4[0]'''<br> <br>
print 'shweta',recs<br> var=StringVar(); <br> for line in recs[1:]:<br> <br> p4 = re.sub('[]''""['']','','%s'%line)<br>
print p4[0]<br> <br> p2 = string.split(p4)<br> print 'p2',p2<br> p5 = []<br> p5 = p5.append(p2[8])<br> print line<br> w=p4[0] # d r _<br>
dirs.insert(END,line)<br> var=StringVar(); <br> #dirs.bind('<Double-1>', listd)<br> <br> textsfile.pack( side = BOTTOM)<br> dirsb.config(command=dirs.yview)<br>
dirs.pack(side=LEFT,fill=BOTH)<br> c=textsfile.get()<br> dirfm.pack()<br> self.loseConnection()<br> reactor.stop()</div>
<div> </div>
<div><br>protocol.ClientCreator(reactor, SimpleTransport).connectTCP(HOST, 22)</div>
<div>reactor.run()<br></div>
<div> </div>
<div> </div>
<div> </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"><<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>></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 <<a href="mailto:shweta3230@gmail.com" target="_blank">shweta3230@gmail.com</a>> 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'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>