def lineReceived(self, line): name = line.strip() if name in self.factory.allowedList: f = self.factory.allowedList[name][0] df = self.factory.allowedList[name][1] # print "Sending " + name buf = f.read() self.transport.write(buf) f.close() df.callback("Closed") del self.factory.allowedList[name] else: try: # Sanitize input: name = os.path.join(self.factory.dirname, os.path.basename(name)) # This is bad: for example, try sending "/etc/passwd" to the server #path = os.path.join(self.factory.dirname,name) f = ChunkFile(name) print "Sending " + name buf = f.read() self.transport.write(buf) f.close() except IOError: print "File " + name + " not found" self.transport.loseConnection()
def archive(self, storageDir): self.fileName = os.path.join(storageDir, self.name) tar = tarfile.open(self.fileName, 'w:bz2') files = os.listdir(self.realdir) #print files for fname in files: path = os.path.join(self.realdir, fname) if (os.path.isdir(path)): tar.add(path, fname, recursive=False) #continue else: #print "archive: " + fname tar.add(path, fname) tar.close() self.chunkfile = ChunkFile(self.fileName) return self.chunkfile