def remove(self, files): sftp = self.client.open_sftp() rfs = sgb.glob(sftp, files) for rf in rfs: if not sgb.lexists(sftp, rf): continue if sgb.isdir(sftp, rf): self.remove(pp.join(rf+'*')) sftp.rmdir(rf) else: sftp.remove(rf)
def remove(self, files): sftp = self.client.open_sftp() rfs = sgb.glob(sftp, files) for rf in rfs: if not sgb.lexists(sftp, rf): continue if sgb.isdir(sftp, rf): self.remove(pp.join(rf + '*')) sftp.rmdir(rf) else: sftp.remove(rf)
def get(self, rfiles, ldir): sftp = self.client.open_sftp() rfiles = self.convertPath(rfiles) rfs = sgb.glob(sftp, rfiles) if len(rfs) > 0: self.checkLocalPath(ldir) print 'get remote:{:}'.format(rfiles),\ '-> local:{:}'.format(ldir) for rf in rfs: if not sgb.isdir(sftp, rf): lf = op.join(ldir, pp.basename(rf)) sftp.get(rf, lf) os.chmod(lf, sftp.stat(rf).st_mode)
def getdir(self, rdir, ldir, files=['*']): for f in files: self.get(pp.join(rdir, f), ldir) sftp = self.client.open_sftp() for f in sftp.listdir(rdir): rf = pp.join(rdir, f) if sgb.isdir(sftp, rf): self.getdir(rf, op.join(ldir, f), files)
def checkRemotePath(self, sftp, d): if d == '': return if not sgb.lexists(sftp, d): self.checkRemotePath(sftp, pp.dirname(d)) sftp.mkdir(d, mode=0755)