Ejemplo n.º 1
0
    def test_progress_ftp(self):
        progress = ProgressPrinter(stream=sys.stdout)

        request = FTPRequest('ftp://example.com/example.txt')
        response = FTPResponse()
        response.reply = FTPReply(226, 'Closing data connection')
        response.file_transfer_size = 2048
        response.restart_value = 10

        progress.update_from_begin_request(request)
        progress.update_from_begin_response(response)

        for dummy in range(100):
            progress.update_with_data(b'abc')

        progress.update_from_end_response(response)
Ejemplo n.º 2
0
    def start(self, request: Request) -> Response:
        '''Start a file or directory listing download.

        Args:
            request: Request.

        Returns:
            A Response populated with the initial data connection reply.

        Once the response is received, call :meth:`download`.

        Coroutine.
        '''
        if self._session_state != SessionState.ready:
            raise RuntimeError('Session not ready')

        response = Response()

        yield from self._prepare_fetch(request, response)

        response.file_transfer_size = yield from self._fetch_size(request)

        if request.restart_value:
            try:
                yield from self._commander.restart(request.restart_value)
                response.restart_value = request.restart_value
            except FTPServerError:
                _logger.debug('Could not restart file.', exc_info=1)

        yield from self._open_data_stream()

        command = Command('RETR', request.file_path)

        yield from self._begin_stream(command)

        self._session_state = SessionState.file_request_sent

        return response
Ejemplo n.º 3
0
    def start(self, request: Request) -> Response:
        """Start a file or directory listing download.

        Args:
            request: Request.

        Returns:
            A Response populated with the initial data connection reply.

        Once the response is received, call :meth:`download`.

        Coroutine.
        """
        if self._session_state != SessionState.ready:
            raise RuntimeError("Session not ready")

        response = Response()

        yield from self._prepare_fetch(request, response)

        response.file_transfer_size = yield from self._fetch_size(request)

        if request.restart_value:
            try:
                yield from self._commander.restart(request.restart_value)
                response.restart_value = request.restart_value
            except FTPServerError:
                _logger.debug("Could not restart file.", exc_info=1)

        yield from self._open_data_stream()

        command = Command("RETR", request.file_path)

        yield from self._begin_stream(command)

        self._session_state = SessionState.file_request_sent

        return response