Esempio n. 1
0
 def _handle_read(self, sock, req_data):
     size, offset = self._read_struct.unpack(req_data[:16])
     path = self.get_full_path(req_data[16:].decode('utf8'))
     
     with open(path, 'rb') as f:
         f.seek(offset)
         ellnet.send_block(sock, f.read(size))
Esempio n. 2
0
    def _handle_listing_req(self, sock, req_data):
        path = self.get_full_path(req_data.decode('utf8'))
        
        strs = []
        for fn in os.listdir(path):
            file_path = os.path.join(path, fn)
            if os.path.isdir(file_path):
                size = "-1"
            elif os.path.isfile(file_path):
                size = str(os.path.getsize(file_path))
            else:
                continue

            strs.extend((fn, size))

        data = '\0'.join(strs).encode('utf8')
        ellnet.send_block(sock, data)
Esempio n. 3
0
    def _handle_listing_req(self, sock, req_data):
        path = self.get_full_path(req_data.decode('utf8'))

        strs = []
        for fn in os.listdir(path):
            file_path = os.path.join(path, fn)
            if os.path.isdir(file_path):
                size = "-1"
            elif os.path.isfile(file_path):
                size = str(os.path.getsize(file_path))
            else:
                continue

            strs.extend((fn, size))

        data = '\0'.join(strs).encode('utf8')
        ellnet.send_block(sock, data)