IBM API Hub
IBM Aspera Transfer SDK

By IBM Aspera

The IBM Aspera Transfer SDK allows you to initiate, monitor and control file transfers and streams.


Use Java to upload a stream as a stream

This page breaks down the sample code into individual steps so you can evaluate how to customize the code for your application.

To run the full Java® sample code for uploading a file, go to the /api folder in the installation directory.

For more information on using gRPC to help develop your language-specific client, see Quick start guide for Java

Create a connection to the TransferD daemon.


    // Java example
    TransferServiceGrpc.TransferServiceBlockingStub client = TransferServiceGrpc.newBlockingStub(
        ManagedChannelBuilder.forAddress("localhost", 55002)
            .usePlaintext()
            .build()
    );    

Create the transfer specification

The transfer specification (transferSpec) defines the parameters for the transfer. In this type of transfer, you must specify the URI. The parameter "direction":"send" indicates that the transfer is an upload.

For more information, see transferSpec Definition.

NOTE: For a complete description of the parameters that are in the transferSpec, see: transferd.html, transderd.md, or transfer.proto that are in the /api directory.

// java example
        String transferSpec = "{"
        + "  \"session_initiation\": {"
        + "    \"ssh\": {"
        + "      \"ssh_port\": 22,"
        + "      \"remote_user\": \"root\","
        + "      \"remote_password\": \"aspera\""
        + "    }"
        + "  },"
        + "  \"direction\": \"send\","
        + "  \"remote_host\": \"172.0.0.2\","
        + "  \"assets\": {"
        + "    \"paths\": ["
        + "      {"
        + "        \"source\": \"tcp://127.0.0.1:33333\","
        + "        \"destination\": \"tcp://127.0.0.1:33333\""
        + "      }"
        + "    ]"
        + "  }"
        + "}";
    

Start the transfer

This example shows a transfer definition with these elements:

Transfer definition elements
transferType Identifies the transfer type, which in this example is URL_STREAM_TO_STREAM.
config Optional values for configuring the transfer.
transferSpec The transfer specification created in the previous step.
// java example
        Iterator transferResponseIterator = client.startTransferWithMonitor(
                Transfer.TransferRequest.newBuilder()
                    .setTransferType(Transfer.TransferType.URL_STREAM_TO_STREAM)
                    .setConfig(
                        Transfer.TransferConfig.newBuilder().build()
                    )
                    .setTransferSpec(transferSpec)
                    .build()
            );
            

Monitor the transfer until it finishes

// java example
        transferResponseIterator.forEachRemaining(pResponse ->
        System.out.println("transfer response " + pResponse)
    );
    
Legend
Technologies
Products & Services
Company information
Company logoIBM Aspera