dxlfiletransferclient.client module

class dxlfiletransferclient.client.FileSendResult(file_id, size, hashes)

Bases: object

Class which holds the result data from a file send attempt.

file_id

Id of the file

Return type:str
hashes

Hashes computed for the file. Each item in the return dictionary should have a key defined in the dxlfiletransferclient.constants.HashType class and a corresponding value containing a hexstring computed for the hash type.

Return type:dict
size

Size of the file

Return type:int
to_dict()

Return a dictionary representation of this result object.

Returns:The dictionary representation
Return type:dict
class dxlfiletransferclient.client.FileSendSegmentResult(file_id, segments_received, file_result=None, total_segments=None)

Bases: object

Class which holds the result data from a file send segment request.

file_id

Id of the file

Return type:str
file_result

Storage result for the entire file (not just the segment), a member of the dxlfiletransferclient.constants.FileStoreResultProp class. If the stored segment was not the last one for the file, the return value would be dxlfiletransferclient.constants.FileStoreResultProp.NONE.

Return type:str
segments_received

Number of segments received so far for the file

Return type:int
total_segments

Total number of segments in the file. If the total number of segments is unknown, None is returned.

Return type:int
class dxlfiletransferclient.client.FileTransferClient(dxl_client, send_file_topic='/opendxl-file-transfer/service/file-transfer/file/store')

Bases: dxlbootstrap.client.Client

The "File Transfer DXL Python client" client wrapper class.

Constructor parameters:

Parameters:
  • dxl_client (dxlclient.client.DxlClient) -- The DXL client to use for communication with the fabric.
  • send_file_topic (str) -- Topic name to use for file send operations.
send_file_from_stream_request(stream, file_name_on_server, stream_size=None, max_segment_size=51200, total_segments=None, callback=None)

Send the contents of a stream as request messages to the DXL fabric. This method presumes that a service registered with the DXL fabric will provide response messages for the requests which are sent.

Example:

from io import BytesIO
from dxlfiletransferclient import FileTransferClient
from dxlclient.client import DxlClient

# Create the client
with DxlClient(config) as dxl_client:

    # Connect to the fabric
    dxl_client.connect()

    # Create client wrapper
    client = FileTransferClient(dxl_client)

    # Create a byte stream
    some_bytes = BytesIO(b'a long stream of bytes')

    # Send byte stream to the service, to be stored remotely as a
    # file named "stored.txt".
    resp = client.send_file_from_stream_request(
        some_bytes, "stored.txt")
Parameters:
  • stream -- The IO stream from which to read bytes for the send request.
  • file_name_on_server (str) -- Name that the file should be stored as on the server. The name may contain subdirectories if it is desired to store the file in a subdirectory under the base storage directory on the server, for example, localsubdir/stored.txt.
  • stream_size (int) -- Total size of the local stream (None if not known).
  • max_segment_size (int) -- Maximum size (in bytes) for each file segment transferred through the DXL fabric.
  • total_segments (int) -- Total number of segments that the stream will be sent across in (None if not known).
  • callback -- Optional callable object called back upon with results for each transferred segment. The parameter passed into the callback should be an FileSendSegmentResult instance.
Returns:

The result of the send request.

Return type:

FileSendResult

send_file_request(file_name_to_send, file_name_on_server=None, max_segment_size=51200, callback=None)

Send the contents of a file as request messages to the DXL fabric. This method presumes that a service registered with the DXL fabric will provide response messages for the requests which are sent.

Example:

from dxlfiletransferclient import FileTransferClient
from dxlclient.client import DxlClient

# Create the client
with DxlClient(config) as dxl_client:

    # Connect to the fabric
    dxl_client.connect()

    # Create client wrapper
    client = FileTransferClient(dxl_client)

    # Send the contents of a local file, "/root/localfile.txt", to
    # be stored remotely as a file named "stored.txt".
    resp = client.send_file_request("/root/localfile.txt",
        "stored.txt")
Parameters:
  • file_name_to_send (str) -- Path to the locally accessible file which should be sent.
  • file_name_on_server (str) -- Name that the file should be stored as on the server. The name may contain subdirectories if it is desired to store the file in a subdirectory under the base storage directory on the server, for example, localsubdir/stored.txt. If no value is set for this parameter, the base name of the file specified in the file_name_to_send parameter is used. For example, if file_name_on_server were not specified but file_name_to_send were specified as /root/localfile.txt, the file stored at the server would be under the root storage directory, with a name of localfile.txt.
  • max_segment_size (int) -- Maximum size (in bytes) for each file segment transferred through the DXL fabric.
  • callback (function) -- Optional callable object called back upon with results for each transferred segment. The parameter passed into the callback should be a FileSendSegmentResult instance.
Returns:

The result of the send request.

Return type:

FileSendResult