protocol.ftp.command Module

FTP service control.

class wpull.protocol.ftp.command.Commander(data_stream)[source]

Bases: object

Helper class that performs typical FTP routines.

Parameters:control_stream (ftp.stream.ControlStream) – The control stream.
begin_stream(command: wpull.protocol.ftp.request.Command) → wpull.protocol.ftp.request.Reply[source]

Start sending content on the data stream.

Parameters:
  • command – A command that tells the server to send data over the
  • connection. (data) –

Coroutine.

Returns:The begin reply.
login(username: str='anonymous', password: str='-wpull-lib@')[source]

Log in.

Coroutine.

passive_mode() → typing.Tuple[source]

Enable passive mode.

Returns:The address (IP address, port) of the passive port.

Coroutine.

classmethod raise_if_not_match(action: str, expected_code: typing.Union, reply: wpull.protocol.ftp.request.Reply)[source]

Raise FTPServerError if not expected reply code.

Parameters:
  • action – Label to use in the exception message.
  • expected_code – Expected 3 digit code.
  • reply – Reply from the server.
read_stream(file: typing.IO, data_stream: wpull.protocol.ftp.stream.DataStream) → wpull.protocol.ftp.request.Reply[source]

Read from the data stream.

Parameters:
  • file – A destination file object or a stream writer.
  • data_stream – The stream of which to read from.

Coroutine.

Returns:The final reply.
Return type:Reply
read_welcome_message()[source]

Read the welcome message.

Coroutine.

restart(offset: int)[source]

Send restart command.

Coroutine.

setup_data_stream(connection_factory: typing.Callable, data_stream_factory: typing.Callable=<class 'wpull.protocol.ftp.stream.DataStream'>) → wpull.protocol.ftp.stream.DataStream[source]

Create and setup a data stream.

This function will set up passive and binary mode and handle connecting to the data connection.

Parameters:
  • connection_factory – A coroutine callback that returns a connection
  • data_stream_factory – A callback that returns a data stream

Coroutine.

Returns:DataStream
size(filename: str) → int[source]

Get size of file.

Coroutine.