Exemplo n.º 1
0
 def list_folder(self, path):
     """ List contents of a folder. """
     self.log.debug('list_folder({0!r})'.format(path))
     rpath = self._realpath(path)
     if not self.user.is_sysop and self._is_uploaddir(path):
         return []
     try:
         out = []
         if path == u'/':
             out.append(self._dummy_dir_stat())
         elif flagged_dirname in path:
             self.flagged = self.user.get('flaggedfiles', set())
             for fname in self.flagged:
                 rname = fname
                 attr = SFTPAttributes.from_stat(os.stat(rname))
                 attr.filename = fname[fname.rindex('/') + 1:]
                 out.append(attr)
             return out
         flist = os.listdir(rpath)
         for fname in flist:
             attr = SFTPAttributes.from_stat(
                 os.stat(os.path.join(rpath, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError as err:
         return SFTPServer.convert_errno(err.errno)
Exemplo n.º 2
0
 def _dummy_dir_stat(self):
     """ Stat on our dummy __flagged__ directory. """
     self.log.debug('_dummy_dir_stat')
     attr = SFTPAttributes.from_stat(
         os.stat(self.root))
     attr.filename = flagged_dirname
     return attr
Exemplo n.º 3
0
 def stat(self):
     """ Stat the file descriptor. """
     self.log.debug('stat')
     try:
         return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
     except OSError as err:
         return SFTPServer.convert_errno(err.errno)
Exemplo n.º 4
0
Arquivo: sftp.py Projeto: tehmaze/x84
 def lstat(self, path):
     self.log.debug('lstat({0!r})'.format(path))
     if path.endswith(flagged_dirname):
         return self._dummy_dir_stat()
     elif path.find(flagged_dirname) > -1:
         for f in self.flagged:
             fstripped = f[f.rindex(os.path.sep) + 1:]
             pstripped = path[path.rindex('/') + 1:]
             if fstripped == pstripped:
                 self.log.debug('file is actually {0}'.format(f))
                 return SFTPAttributes.from_stat(f)
     path = self._realpath(path)
     try:
         return SFTPAttributes.from_stat(os.lstat(path))
     except OSError as err:
         return SFTPServer.convert_errno(err.errno)
Exemplo n.º 5
0
 def lstat(self, path):
     path = self._realpath(path)
     try:
         return SFTPAttributes.from_stat(os.lstat(path))
     except OSError:
         e = sys.exc_info()[1]
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 6
0
 def stat(self):
     """
     This method performs the stat attributes
     return path SFTPAttributes or error
     """
     try:
         return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
     except OSError, e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 7
0
 def lstat(self, path):
     """
     This method performs the lstat attributes for the given path
     path - file/folder path
     return lstat SFTPAttributes or error
     """
     path = self._realpath(path)
     try:
         return SFTPAttributes.from_stat(os.lstat(path))
     except OSError, e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 8
0
 def list_folder(self, path):
     path = self._realpath(path)
     try:
         out = [ ]
         flist = os.listdir(path)
         for fname in flist:
             attr = SFTPAttributes.from_stat(os.stat(os.path.join(path, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 9
0
 def list_folder(self, path):
     path = self._realpath(path)
     try:
         out = []
         flist = os.listdir(path)
         for fname in flist:
             attr = SFTPAttributes.from_stat(os.stat(os.path.join(path, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 10
0
 def lstat(self, path: Text) -> Union[SFTPAttributes, int]:
     self.session.sftp_client_ready.wait()
     args, _ = SFTPProxyReplaceHandler.parser().parse_known_args()
     if self.session.sftp_client is None:
         raise MissingClient("self.session.sftp_client is None!")
     stat_remote = self.session.sftp_client.lstat(path)
     if isinstance(stat_remote, int):
         return stat_remote
     stat_replace = SFTPAttributes.from_stat(
         os.stat(args.sftp_replacement_file))
     stat_remote.st_size = stat_replace.st_size
     return stat_remote
Exemplo n.º 11
0
 def lstat(self, path):
     try:
         if path == "/":
             return self._dir_attr()
         else:
             parent = os.path.split(path)[0]
             if parent == '/':
                 return self._dir_attr()
             else:
                 path = self._realpath(path)
                 return SFTPAttributes.from_stat(os.lstat(path))
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 12
0
 def stat(self, path):
     try:
         # If the root path send a simple directory attribute object
         if path == "/":
             return self._dir_attr()
         else:
             parent = os.path.split(path)[0]
             if parent == '/':
                 return self._dir_attr()
             else:
                 path = self._realpath(path)
                 return SFTPAttributes.from_stat(os.stat(path))
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 13
0
def get_local_files(root: str,
                    rel_path: str,
                    normalize=os.path.normpath,
                    joinpath=os.path.join):
    local_path = normalize(joinpath(root, rel_path))
    logger.debug("local: %s", local_path)
    try:
        generator = os.scandir(local_path)
    except FileNotFoundError:
        return {}
    return {
        ent.name: SFTPAttributes.from_stat(ent.stat(follow_symlinks=False),
                                           ent.name)
        for ent in generator if not ent.is_symlink()
    }
Exemplo n.º 14
0
 def list_folder(self, path):
     """
     This method returns the list folder given a path
     path - path to folder
     return a list of folders
     """
     path = self._realpath(path)
     try:
         out = [ ]
         flist = os.listdir(path)
         for fname in flist:
             attr = SFTPAttributes.from_stat(os.stat(os.path.join(path, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError, e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 15
0
 def list_folder(self, path):
     """
     This method returns the list folder given a path
     path - path to folder
     return a list of folders
     """
     path = self._realpath(path)
     try:
         out = []
         flist = os.listdir(path)
         for fname in flist:
             attr = SFTPAttributes.from_stat(
                 os.stat(os.path.join(path, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError, e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 16
0
 def list_folder(self, path):
     path = self._realpath(path)
     try:
         out = []
         # TODO: win32 incorrectly lists paths with non-ascii if path is not
         # unicode. However on Linux the server should only deal with
         # bytestreams and posix.listdir does the right thing
         if sys.platform == 'win32':
             flist = [f.encode('utf8') for f in os.listdir(path)]
         else:
             flist = os.listdir(path)
         for fname in flist:
             attr = SFTPAttributes.from_stat(os.stat(pathjoin(path, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError, e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 17
0
 def list_folder(self, path):
     path = self._realpath(path)
     try:
         out = [ ]
         # TODO: win32 incorrectly lists paths with non-ascii if path is not
         # unicode. However on Linux the server should only deal with
         # bytestreams and posix.listdir does the right thing 
         if sys.platform == 'win32':
             flist = [f.encode('utf8') for f in os.listdir(path)]
         else:
             flist = os.listdir(path)
         for fname in flist:
             attr = SFTPAttributes.from_stat(os.stat(pathjoin(path, fname)))
             attr.filename = fname
             out.append(attr)
         return out
     except OSError, e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 18
0
 def lstat(self, path):
     path = self._realpath(path)
     try:
         return SFTPAttributes.from_stat(os.lstat(path))
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 19
0
 def stat(self):
     try:
         return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 20
0
 def stat(self, path):
     path = self._realpath(path)
     try:
         return SFTPAttributes.from_stat(os.stat(path))
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 21
0
Arquivo: sftp.py Projeto: tehmaze/x84
 def _dummy_dir_stat(self):
     self.log.debug('_dummy_dir_stat')
     attr = SFTPAttributes.from_stat(
         os.stat(self.root))
     attr.filename = flagged_dirname
     return attr
Exemplo n.º 22
0
 def stat(self):
     try:
         return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
     except OSError as e:
         return SFTPServer.convert_errno(e.errno)
Exemplo n.º 23
0
 def _dummy_dir_stat(self):
     """ Stat on our dummy __flagged__ directory. """
     self.log.debug('_dummy_dir_stat')
     attr = SFTPAttributes.from_stat(os.stat(self.root))
     attr.filename = flagged_dirname
     return attr