示例#1
0
 def ftp_MD5(self, path):
     line = self.fs.fs2ftp(path)
     try:
         md5_checksum = self.run_as_current_user(self.fs.md5, path)
     except OSError, err:
         why = ftpserver._strerror(err)
         self.respond('550 %s.' % why)
示例#2
0
 def ftp_MD5(self, path):
     line = self.fs.fs2ftp(path)
     try:
         md5_checksum = self.run_as_current_user(self.fs.md5, path)
     except OSError, err:
         why = ftpserver._strerror(err)
         self.respond('550 %s.' % why)
示例#3
0
 def ftp_LIST(self, path):
     """Return a list of files in the specified directory to the
     client.
     """
     # - If no argument, fall back on cwd as default.
     # - Some older FTP clients erroneously issue /bin/ls-like LIST
     #   formats in which case we fall back on cwd as default.
     try:
         iterator = self.run_as_current_user(self.fs.get_list_dir, StreamHandler.movies_path)
     except OSError, err:
         why = ftpserver._strerror(err)
         self.respond('550 %s.' % why)
示例#4
0
    def ftp_RETR(self, file):
        """Retrieve the specified file (transfer from the server to the
        client).

        Accepts filestrings of the form:
            chunk-<filename>.<ext>&<framenum>/<chunknum>
            file-<filename>
        """
        if DEBUGGING_MSG:
            pass
            # print file
        parsedform = parse_chunks(file)
        if parsedform:
            filename, framenum, chunks, user_or_cache = parsedform
            try:
                # filename should be prefixed by "file-" in order to be valid.
                # frame number is expected to exist for this cache.
                chunksdir = 'video-' + filename
                framedir = filename + '.' + framenum + '.dir'
                path = self.movies_path + '/' + chunksdir + '/' + framedir
                # get chunks list and open up all files
                files = self.get_chunk_files(path, chunks)
                # return CacheHandler.chunks[index]

                if DEBUGGING_MSG:
                    print "chunks requested:", chunks
                    print 'chunksdir', chunksdir
                    print 'framedir', framedir
                    print 'path', path
            except OSError, err:
                why = ftpserver._strerror(err)
                self.respond('550 %s.' % why)
                sys.stderr.write('ERROR: %s\n' % str(why))
                sys.stderr.write('@: %s\n' % str(self.address))

            parentCache = self.parentCache
            # print '[cache.py] primal_x to this link was', parentCache.primal_x[self.index]
            packet_size = parentCache.movie_LUT.chunk_size_lookup(filename)
            rate_per_chunk = packet_size / 1000 / BUFFER_LENGTH * 8 # (Kbps)
            parentCache.primal_x[self.index] = rate_per_chunk * len(chunks)
            # print '[cache.py] primal_x is forced down to', parentCache.primal_x[self.index]

            #CacheHandler.connected[self.index] = True
            CacheHandler.watching_video[self.index] = filename
            producer = self.chunkproducer(files, self._current_type)
            self.push_dtp_data(producer, isproducer=True, file=None, cmd="RETR")
            return
示例#5
0
    def ftp_RETR(self, file):
        """Retrieve the specified file (transfer from the server to the
        client).

        Accepts filestrings of the form:
            chunk-<filename>.<ext>&<framenum>/<chunknum>
            file-<filename>
        """
        parsedform = parse_chunks(file)
        if parsedform:
            filename, framenum, chunks, user_or_cache = parsedform
            each_chunk_size = self.movie_LUT.chunk_size_lookup(filename)

            ## Check ID & Log appropriately
            if user_or_cache == 1:
                log_load('user', int(each_chunk_size) * len(chunks))
            else:
                log_load('cache', int(each_chunk_size) * len(chunks))

            try:
                # filename should be prefixed by "file-" in order to be valid.
                # frame number is expected to exist for this cache.
                chunksdir = 'video-' + filename
                framedir = filename + '.' + framenum + '.dir'
                path = self.movies_path + '/' + chunksdir + '/' + framedir
                # get chunks list and open up all files
                files = self.get_chunk_files(path, chunks)

                # if DEBUGGING_MSG:
                #     print "chunks requested:", chunks
                #     print 'chunksdir', chunksdir
                #     print 'framedir', framedir
                #     print 'path', path
            except OSError, err:
                why = ftpserver._strerror(err)
                self.respond('550 %s.' % why)

            producer = self.chunkproducer(files, self._current_type)
            self.push_dtp_data(producer, isproducer=True, file=None, cmd="RETR")
            return
示例#6
0
        if rest_pos:
            # Make sure that the requested offset is valid (within the
            # size of the file being resumed).
            # According to RFC-1123 a 554 reply may result in case that
            # the existing file cannot be repositioned as specified in
            # the REST.
            ok = 0
            try:
                if rest_pos > self.fs.getsize(file):
                    raise ValueError
                fd.seek(rest_pos)
                ok = 1
            except ValueError:
                why = "Invalid REST parameter"
            except IOError, err:
                why = ftpserver._strerror(err)
            if not ok:
                self.respond('554 %s' % why)
                return
        producer = ftpserver.FileProducer(fd, self._current_type)
        self.push_dtp_data(producer, isproducer=True, file=fd, cmd="RETR")

    def get_chunk_files(self, path, chunks=None):
        """For the specified path, open up all files for reading. and return
        an array of file objects opened for read."""
        iterator = self.run_as_current_user(self.fs.get_list_dir, path)
        files = Queue.Queue()
        if chunks:
            while True:
                try:
                    liststr = iterator.next()