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 |
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 |
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): |
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] |
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: |
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] != '/': |
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 |
|
|