Tftp

InternalTftp Internally serves files using the Trivial File Transfer Protocol.
ExternalTftp Defines a ExternalTftp object, which is actually TFTP client.
InternalTftp.get_address Returns the ipv4 address of this server.
InternalTftp.get_file Download a file from the tftp server to local_path.
InternalTftp.kill Kills the InternalTftpServer.
InternalTftp.put_file Upload a file from src to dest on the tftp server (path).
ExternalTftp.get_address Return the ip address of the ExternalTftp server.
ExternalTftp.get_file Download a file from the ExternalTftp Server.
ExternalTftp.put_file Uploads a file to the tftp server.
class InternalTftp(ip_address=None, port=0, verbose=False)[source]

Bases: object

Internally serves files using the Trivial File Transfer Protocol.

>>> # Typical instantiation ...
>>> from cxmanage_api.tftp import InternalTftp
>>> i_tftp = InternalTftp()
>>> # Alternatively, you can specify an address or hostname ...
>>> i_tftp = InternalTftp(ip_address='localhost')
Parameters:
  • ip_address (string) – Ip address for the Internal TFTP server to use.
  • port (integer) – Port for the internal TFTP server.
  • verbose (boolean) – Flag to turn on additional messaging.
get_address(relative_host=None)[source]

Returns the ipv4 address of this server. If a relative_host is specified, then we discover our address to them.

>>> i_tftp.get_address(relative_host='10.10.14.150')
'localhost'
Parameters:relative_host (string) – Ip address to the relative host.
Returns:The ipv4 address of this InternalTftpServer.
Return type:string
get_file(src, dest)[source]

Download a file from the tftp server to local_path.

>>> i_tftp.get_file(src='remote_file_i_want.txt', dest='/local/path')
Parameters:
  • src (string) – Source file path on the tftp_server.
  • dest (string) – Destination path (on your machine) to copy the TFTP file to.
kill()[source]

Kills the InternalTftpServer.

>>> i_tftp.kill()
put_file(src, dest)[source]

Upload a file from src to dest on the tftp server (path).

>>> i_tftp.put_file(src='/local/file.txt', dest='remote_file_name.txt')
Parameters:
  • src (string) – Path to the local file to send to the TFTP server.
  • dest (string) – Path to put the file to on the TFTP Server.
class ExternalTftp(ip_address, port=69, verbose=False)[source]

Bases: object

Defines a ExternalTftp object, which is actually TFTP client.

>>> from cxmanage_api.tftp import ExternalTftp
>>> e_tftp = ExternalTftp(ip_address='1.2.3.4')
Parameters:
  • ip_address (string) – Ip address of the TFTP server.
  • port (integer) – Port to the External TFTP server.
  • verbose (boolean) – Flag to turn on verbose output (cmd/response).
get_address(relative_host=None)[source]

Return the ip address of the ExternalTftp server.

>>> e_tftp.get_address()
'1.2.3.4'
Parameters:relative_host (None) – Unused parameter present only for function signature.
Returns:The ip address of the external TFTP server.
Return type:string
get_file(src, dest)[source]

Download a file from the ExternalTftp Server.

Note

  • TftpClient is not threadsafe, so we create a unique instance for each transfer.
>>> e_tftp.get_file(src='remote_file_i_want.txt', dest='/local/path')
Parameters:
  • src (string) – The path to the file on the Tftp server.
  • dest (string) – The local destination to copy the file to.
Raises:
  • TftpException – If the file does not exist or cannot be obtained from the TFTP server.
  • TftpException – If a TypeError is received from tftpy.
put_file(src, dest)[source]

Uploads a file to the tftp server.

Note

  • TftpClient is not threadsafe, so we create a unique instance for each transfer.
>>> e_tftp.put_file(src='local_file.txt', dest='remote_name.txt')
Parameters:
  • src (string) – Source file path (on your local machine).
  • dest (string) – Destination path (on the TFTP server).
Raises:
  • TftpException – If the file cannot be written to the TFTP server.
  • TftpException – If a TypeError is received from tftpy.

Previous topic

Image

Next topic

SIMG