Mark.Brown at greenskycredit.com
Thu Mar 11 22:50:33 EST 2010
Yeah, I've looked everywhere for a sftp web client, and did find one written as a java applet. Unfortunately, I want pure html and not an embedded applet in a webpage. Can you expand some more on what you mean by this: "You then though have to learn WSGI or use one of the WSGI frameworks/toolkits. You still couldn't use traditional session layers though and would need to maintain your own data structure with active pool of connections in memory." Also, I have read some stuff about twisted and cherrypy. Would either of these help me out? Sorry if I am being naive, I am by no means an expert in apache or python. ________________________________________ From: Graham Dumpleton [graham.dumpleton at gmail.com] Sent: Thursday, March 11, 2010 7:32 PM To: Mark Brown Cc: mod_python at modpython.org Subject: Re: [mod_python] Paramiko connection to SFTP web-based client On 12 March 2010 09:09, Mark Brown <Mark.Brown at greenskycredit.com> wrote: > Sorry that I am really, really new to Python but I have run into a wall and > need some help: > > Basically, I am trying to create a web-client for a sftp server. > > > > You enter your user name and password and you authenticate against the sftp > server, see a list of all the files on the server, can browse the server, > and if you click on a link download the file. > > I have tried several different methods to keep the network-resource in the > session, but nothing thus far has worked. My research seems to indicate that > in order to achieve this I would need to write a daemon that handles the > connection, and pass the session id to the daemon to match connection to web > request. > > > > I have found some articles on how to turn a python script into a daemon, but > I need some help understanding what is really going. > > Anyways, the script I have tested thus far using mod_python is below: > > > > from mod_python import apache > from mod_python import Session > import paramiko > > > > def handler(req): > session=Session.Session(req) > req.content_type="text/html" > > try: > session['hits'] +=1 > #dirlist=session['sftp'].listdir('.') > req.write('From Session') > except: > t=paramiko.Transport(('[SERVER NAME],22)) > t.connect(username='[USER NAME]',password='[PASSWORD]') > sftp=paramiko.SFTPClient.from_transport(t) > dirlist = sftp.listdir('.') > session['hits']=1 > session['sftp']=sftp > req.write('New Session') > > session.save() > req.write('Hits %d\n' % session['hits']) > req.write(dirlist) > > return apache.OK To ensure portability and overall guarantee it will always work, you should only store in session basic Python data types. Even class objects should be avoided even if they can be pickled. This is because normally the session is stored in a database outside of the process. Complex objects such as a socket handle obviously cant therefore be stored. The only time doing so would work is on Windows. That is because in that case the session database is in memory and isn't actually written to a separate database. You could only make it work on UNIX systems by changing your Apache configuration such that it only ever used a single server child process such that all requests handled by same process and forcing the use of in memory session database. Forcing a single process when using mod_python on UNIX sort of defeats the problem of using Apache. You could use this single process model by instead using mod_wsgi as at least with that you could use its daemon mode and force your web application to run in single dedicated process separate to the Apache server child processes. You then though have to learn WSGI or use one of the WSGI frameworks/toolkits. You still couldn't use traditional session layers though and would need to maintain your own data structure with active pool of connections in memory. BTW, are you sure there aren't already web interfaces to SFTP clients? Sure there would be one somewhere, albeit maybe implemented in a different language. Graham -- This message was scanned by ESVA and is believed to be clean. This electronic message transmission contains information from GreenSky Trade Credit, LLC which may be confidential & privileged. Recipients should not file copies of this e-mail with publicly accessed records. The information is intended to be for the use of the individual(s) named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of this message is prohibited. If you have received this electronic transmission in error, please notify us by e-mail immediately.