Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Python: Общие вопросы > Модификация pyftpdlib


Автор: Martiner 8.9.2009, 07:05
Помогите пожалуйсто в следующем вопросе: необходимо "модифицировать" либу следующим образом: нужно, чтобы в ф-ции "ftp_STOR" данные, которые пришли по FTP в виде файла и должны "упасть" в файловую систему не "падали" туда; поток с этими данными должен отпарсиваться нужным образом....
Собственно, вопрос:
__ где "место", где он пишет на диск ново пришедший файл?
__ как "добраться" до потока с данными ("буфера"), в который пишется ново пришедший файл?

Заранее спасибо! smile


http://code.google.com/p/pyftpdlib/ -- сайт проджекта
http://pyftpdlib.googlecode.com/files/p … 5.1.tar.gz -- либа собственной персоны

Ф-ция, где происходит прием нового файла и по логики должна быть запись на диск или в буфер:
Код

    def ftp_STOR(self, file, mode='w'):
        """Store a file (transfer from the client to the server)."""
        # A resume could occur in case of APPE or REST commands.
        # In that case we have to open file object in different ways:
        # STOR: mode = 'w'
        # APPE: mode = 'a'
        # REST: mode = 'r+' (to permit seeking on file object)
        if 'a' in mode:
            cmd = 'APPE'
        else:
            cmd = 'STOR'
        line = self.fs.fs2ftp(file)
        rest_pos = self.restart_position
        self.restart_position = 0
        if rest_pos:
            mode = 'r+'
        try:
            fd = self.run_as_current_user(self.fs.open, file, mode + 'b')
        except IOError, err:
            why = _strerror(err)
            self.log('FAIL %s "%s". %s.' %(cmd, line, why))
            self.respond('550 %s.' %why)
            return

        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:
                assert not rest_pos > self.fs.getsize(file)
                fd.seek(rest_pos)
                ok = 1
            except AssertionError:
                why = "Invalid REST parameter"
            except IOError, err:
                why = _strerror(err)
            if not ok:
                self.respond('554 %s' %why)
                self.log('FAIL %s "%s". %s.' %(cmd, line, why))
                return

        self.log('OK %s "%s". Upload starting.' %(cmd, line))
        if self.data_channel is not None:
            self.respond("125 Data connection already open. Transfer starting.")
            self.data_channel.file_obj = fd
            self.data_channel.enable_receiving(self.current_type)
        else:
            self.respond("150 File status okay. About to open data connection.")
            self._in_dtp_queue = fd

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)