[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sshproxy-dev] Changes to sshproxy/SSHproxy/client/console.py
From: |
Pierre-Yves Rofes |
Subject: |
[sshproxy-dev] Changes to sshproxy/SSHproxy/client/console.py |
Date: |
Thu, 27 Oct 2005 10:14:36 -0400 |
Index: sshproxy/SSHproxy/client/console.py
diff -u sshproxy/SSHproxy/client/console.py:1.3
sshproxy/SSHproxy/client/console.py:1.4
--- sshproxy/SSHproxy/client/console.py:1.3 Wed Aug 3 13:40:37 2005
+++ sshproxy/SSHproxy/client/console.py Thu Oct 27 14:14:36 2005
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
+import traceback
import os.path, threading, paramiko
import readline
from cmd import Cmd
@@ -229,7 +229,7 @@
break
except socket.timeout:
pass
-
+
def do_stat(self, arg):
"""
stat filename
@@ -271,14 +271,20 @@
if not arg:
arg = '.'
p = self._realpath(arg)
+ #print 'p = %s' % p
+ #print 'arg = %s' % arg
+ #print '%(p)s %(arg)s' % locals()
if p:
- #self._cache = {}
+ self._cache = {}
self.cache(p, force=1)
+ #print self.cache(p).get()
if self.cache(p).get():
+
self.cwd = p
self.set_prompt()
return
- del self._cache[p]
+ if self._cache.has_key(p):
+ del self._cache[p]
self.stdout.write('No such directory\n')
def complete_lls(self, text, line, begidx, endidx):
@@ -290,6 +296,16 @@
path = self._realpath(path)
if not len(path):
return None
+ # disable cache
+ class NoCache(object):
+ def __init__(self, f, l):
+ self.filename = f
+ self.l = l
+ def get(self):
+ return self.l or [self]
+
+ return NoCache(path, sftp.listdir(path))
+
if force or not self._cache.has_key(path):
self._cache[path] = CacheRemoteDir(sftp, path, self.lock)
return self._cache[path]
@@ -352,6 +368,10 @@
self.stdout.write("%s:\n" % p)
for f in self.cache(p).get():
c = ''
+ #try:
+ # sftp.stat(f.filename)
+ #except IOError:
+ # continue
if self._isdir(os.path.join(p, f.filename)):
c = '/'
if long:
@@ -447,9 +467,9 @@
def do_put(self, arg):
"""
- put local_files...
+ put local_files...
- Upload local files to remote server.
+ Upload local files to remote server.
"""
for file in arg.split():
if file[0] != '/':
@@ -498,15 +518,46 @@
"""
self.stdout.write('\n')
if self.client.sftp:
+ self.client.sftp.close()
del self.client.sftp
self.client.sftp = None
self.save_history()
return True
def do_rmdir(self, arg):
- print "Not yet implemented"
+ """
+ rmdir
- def do_mkdir(self, arg):
- print "Not yet implemented"
+ Remove directory on the remote server.
+ """
+ sftp = self.open_sftp()
+ for dir in arg.split():
+ if dir[0] != '/':
+ d = self._realpath(dir)
+ if not len(d) or d[0] != '/':
+ self.stdout.write("Directory '%s' does not exist\n" % dir)
+ continue
+ else:
+ try:
+ sftp.rmdir(dir)
+ except IOError:
+ self.stdout.write("Error while removing dir: %s\n" % dir)
+
+ def do_mkdir(self, arg):
+ """
+ mkdir
+ Create a directory on the remote server
+ """
+ sftp = self.open_sftp()
+ for dir in arg.split():
+ try:
+ self.stdout.write("do_mkdir...\n")
+ sftp.mkdir(dir, 0777)
+ self.cache(self.cwd, force=1)
+ self.stdout.write("do_mkdir OK\n")
+ except Exception:
+ traceback.print_exc()
+ self.stdout.write("Error mkdir\n")
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [sshproxy-dev] Changes to sshproxy/SSHproxy/client/console.py,
Pierre-Yves Rofes <=