/[sshproxy]/sshproxy/SSHproxy/client/console.py
ViewVC logotype

Diff of /sshproxy/SSHproxy/client/console.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dguerizec, Wed Aug 3 13:40:37 2005 UTC revision 1.4 by pyrofes, Thu Oct 27 14:14:36 2005 UTC
# Line 17  Line 17 
17  # along with this program; if not, write to the Free Software  # along with this program; if not, write to the Free Software
18  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19    
20    import traceback
21  import os.path, threading, paramiko  import os.path, threading, paramiko
22  import readline  import readline
23  from cmd import Cmd  from cmd import Cmd
# Line 229  class SFTPConsole(Cmd): Line 229  class SFTPConsole(Cmd):
229                  break                  break
230              except socket.timeout:              except socket.timeout:
231                  pass                  pass
232            
233      def do_stat(self, arg):      def do_stat(self, arg):
234          """          """
235          stat filename          stat filename
# Line 271  class SFTPConsole(Cmd): Line 271  class SFTPConsole(Cmd):
271          if not arg:          if not arg:
272              arg = '.'              arg = '.'
273          p = self._realpath(arg)          p = self._realpath(arg)
274            #print 'p = %s' % p
275            #print 'arg = %s' % arg
276            #print '%(p)s %(arg)s' % locals()
277          if p:          if p:
278              #self._cache = {}              self._cache = {}
279              self.cache(p, force=1)              self.cache(p, force=1)
280                #print self.cache(p).get()
281              if self.cache(p).get():              if self.cache(p).get():
282                  
283                  self.cwd = p                  self.cwd = p
284                  self.set_prompt()                  self.set_prompt()
285                  return                  return
286              del self._cache[p]              if self._cache.has_key(p):
287                    del self._cache[p]
288          self.stdout.write('No such directory\n')          self.stdout.write('No such directory\n')
289    
290      def complete_lls(self, text, line, begidx, endidx):      def complete_lls(self, text, line, begidx, endidx):
# Line 290  class SFTPConsole(Cmd): Line 296  class SFTPConsole(Cmd):
296          path = self._realpath(path)          path = self._realpath(path)
297          if not len(path):          if not len(path):
298              return None              return None
299            # disable cache
300            class NoCache(object):
301                def __init__(self, f, l):
302                    self.filename = f
303                    self.l = l
304                def get(self):
305                    return self.l or [self]    
306    
307            return NoCache(path, sftp.listdir(path))
308    
309          if force or not self._cache.has_key(path):          if force or not self._cache.has_key(path):
310              self._cache[path] = CacheRemoteDir(sftp, path, self.lock)              self._cache[path] = CacheRemoteDir(sftp, path, self.lock)
311          return self._cache[path]          return self._cache[path]
# Line 352  class SFTPConsole(Cmd): Line 368  class SFTPConsole(Cmd):
368                  self.stdout.write("%s:\n" % p)                  self.stdout.write("%s:\n" % p)
369                  for f in self.cache(p).get():                  for f in self.cache(p).get():
370                      c = ''                      c = ''
371                        #try:
372                        #    sftp.stat(f.filename)
373                        #except IOError:
374                        #    continue
375                      if self._isdir(os.path.join(p, f.filename)):                      if self._isdir(os.path.join(p, f.filename)):
376                          c = '/'                          c = '/'
377                      if long:                      if long:
# Line 447  class SFTPConsole(Cmd): Line 467  class SFTPConsole(Cmd):
467    
468      def do_put(self, arg):      def do_put(self, arg):
469          """          """
470              put local_files...          put local_files...
471    
472                  Upload local files to remote server.              Upload local files to remote server.
473          """          """
474          for file in arg.split():          for file in arg.split():
475              if file[0] != '/':              if file[0] != '/':
# Line 498  class SFTPConsole(Cmd): Line 518  class SFTPConsole(Cmd):
518          """          """
519          self.stdout.write('\n')          self.stdout.write('\n')
520          if self.client.sftp:          if self.client.sftp:
521                self.client.sftp.close()
522              del self.client.sftp              del self.client.sftp
523              self.client.sftp = None              self.client.sftp = None
524          self.save_history()          self.save_history()
525          return True          return True
526    
527      def do_rmdir(self, arg):      def do_rmdir(self, arg):
528          print "Not yet implemented"          """
529                rmdir
530    
531      def do_mkdir(self, arg):                 Remove directory on the remote server.
532          print "Not yet implemented"          """
533            sftp = self.open_sftp()
534            for dir in arg.split():
535              if dir[0] != '/':
536                  d = self._realpath(dir)
537                  if not len(d) or d[0] != '/':
538                      self.stdout.write("Directory '%s' does not exist\n" % dir)
539                      continue
540                  else:
541                      try:
542                          sftp.rmdir(dir)
543                      except IOError:
544                          self.stdout.write("Error while removing dir: %s\n" % dir)
545                          
546    
547        def do_mkdir(self, arg):
548            """
549                mkdir
550    
551                  Create a directory on the remote server
552            """
553            sftp = self.open_sftp()
554            for dir in arg.split():
555                try:
556                    self.stdout.write("do_mkdir...\n")
557                    sftp.mkdir(dir, 0777)
558                    self.cache(self.cwd, force=1)
559                    self.stdout.write("do_mkdir OK\n")
560                except Exception:
561                    traceback.print_exc()
562                    self.stdout.write("Error mkdir\n")
563                    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26