示例#1
0
文件: sftp.py 项目: adammendoza/x84
 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)
示例#2
0
文件: sftp.py 项目: adammendoza/x84
 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
示例#3
0
文件: sftp.py 项目: adammendoza/x84
 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)
示例#4
0
文件: sftp.py 项目: 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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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
示例#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)
示例#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)
示例#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()
    }
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#21
0
文件: sftp.py 项目: 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
示例#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)
示例#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