主要内容

ftpMicroservice

R2026b

MAVLink FTP microservice object

Since R2026b

    Description

    The ftpMicroservice represents the MAVLink File Transfer Protocol (FTP) microservice. This object uses MAVLink FTP messages to exchange files with a remote MAVLink client. Use the object functions to list directory contents, read files, upload files, and remove files from a remote MAVLink client.

    Creation

    To create a ftpMicroservice object, use the mavlinkmicroservice function and specify the microservice type as "ftp":

    ftp = mavlinkmicroservice(mavlinkio,"ftp").

    Properties

    expand all

    MAVLink network identifier, specified as an integer in the range [0, 255]. This property specifies the value of the target_network field of FILE_TRANSFER_PROTOCOL messages generated by the FTP microservice.

    Maximum time, in seconds, that the ftpMicroservice object waits for the required acknowledgment for file transfer protocol operations, specified as a positive scalar. To change this value, use the setTimeout function.

    Number of retry attempts for file transfer protocol operations that do not complete within the timeout period, specified as a nonnegative integer. To change this value, use the setRetry function.

    Object Functions

    listList files and folders in directory on remote MAVLink client
    readRead file from remote MAVLink client
    uploadUpload file to remote MAVLink client
    removeDelete file from remote MAVLink client
    setTimeoutSet microservice timeout value
    setRetrySet microservice retry count

    Examples

    collapse all

    Download and delete flight logs from a Pixhawk® 4 board running PX4® firmware by using the FTP microservice.

    Download the latest version of common.xml file from the MAVLINK Common Message Set (common.xml) section of the MAVLink documentation, then create a mavlinkdialect object using the file.

    dialect = mavlinkdialect("common.xml");

    Create a local MAVLink client by using the mavlinkio object.

    gcs = mavlinkio(dialect);

    Store the remote MAVLink client information by using the mavlinkclient object. This Pixhawk board has a system ID of 1 and a component ID of 1.

    uav = mavlinkclient(gcs,1,1);

    Connect the local MAVLink client to the same serial port as the Pixhawk board by using the connect function. This Pixhawk board uses the COM5 port.

    connect(gcs,"Serial",SerialPort="COM5");

    Create a heartbeat microservice object.

    heartbeat = mavlinkmicroservice(gcs,"heartbeat");

    Start sending the HEARTBEAT messages to the Pixhawk board by using the start function.

    start(heartbeat,uav,"Serial",SerialPort="COM5")

    If the Pixhawk board replies with HEARTBEAT messages, a connection is established.

    Verify that the connection has been established by using the listClients function.

    listClients(gcs)
    ans = 2×4 table
        SystemID    ComponentID       ComponentType             AutopilotType     
        ________    ___________    ____________________    _______________________
    
          255            1            "MAV_TYPE_GCS"        "MAV_AUTOPILOT_INVALID"
           1             1         "MAV_TYPE_QUADROTOR"       "MAV_AUTOPILOT_PX4"

    Create an FTP microservice object.

    ftp = mavlinkmicroservice(gcs,"ftp");

    List the available flight logs stored in the /fs/microsd/log directory of the Pixhawk board by using the list function.

    [status,directory] = list(ftp,uav,"/fs/microsd/log")
    status = true
    directory = 4×3 table
          Type           Name            Size                 
        ________    _______________    _________  
    
          File       2026-03-01.ulg     7340032 
          File       2026-03-02.ulg     7540432 
          File       2026-03-03.ulg     6320031 
          File       2026-03-04.ulg     8221332 
    

    Download the 2026-03-02.ulg flight log into the Documents/logs directory by using the read function.

    [status,~] = read(ftp,uav,"/fs/microsd/log/2026-03-02.ulg", ... 
    LocalPath="Document/logs/2026-03-02.ulg")
    status = true

    After you have downloaded the 2026-03-02.ulg flight log, delete the flight log from the Pixhawk board to save memory space by using the remove function.

    status = remove(ftp,uav,"/fs/microsd/log/2026-03-02.ulg")
    status = true

    Verify that the file has been deleted by using the list function again.

    [status,directory] = list(ftp,uav,"/fs/microsd/log")
    status = true
    directory = 3×3 table
          Type           Name            Size                 
        ________    _______________    _________  
    
          File       2026-03-01.ulg     7340032 
          File       2026-03-03.ulg     6320031 
          File       2026-03-04.ulg     8221332 
    

    Upload a file to a Pixhawk 4 board running PX4 firmware by using the FTP microservice.

    Download the latest version of common.xml file from the MAVLINK Common Message Set (common.xml) section of the MAVLink documentation, then create a mavlinkdialect object using the file.

    dialect = mavlinkdialect("common.xml");

    Create a local MAVLink client by using the mavlinkio object.

    gcs = mavlinkio(dialect);

    Store the remote MAVLink client information by using the mavlinkclient object. This Pixhawk board has a system ID of 1 and a component ID of 1.

    uav = mavlinkclient(gcs,1,1);

    Connect the local MAVLink client to the same serial port as the Pixhawk board by using the connect function. This Pixhawk board uses the COM5 port.

    connect(gcs,"Serial",SerialPort="COM5");

    Create a heartbeat microservice object.

    heartbeat = mavlinkmicroservice(gcs,"heartbeat");

    Start sending the HEARTBEAT messages to the Pixhawk board by using the start function.

    start(heartbeat,uav,"Serial",SerialPort="COM5")

    If the Pixhawk board replies with HEARTBEAT messages, a connection is established.

    Verify that the connection has been established by using the listClients function.

    listClients(gcs)
    ans = 2×4 table
        SystemID    ComponentID       ComponentType             AutopilotType     
        ________    ___________    ____________________    _______________________
    
          255            1            "MAV_TYPE_GCS"        "MAV_AUTOPILOT_INVALID"
           1             1         "MAV_TYPE_QUADROTOR"       "MAV_AUTOPILOT_PX4"

    Create an FTP microservice object.

    ftp = mavlinkmicroservice(gcs,"ftp");

    Upload the camera_intrinsics.json file located in the calib directory into the /fs/microsd/system/calibration directory by using the upload function.

    localPath = "calib/camera_intrinsics.json";
    remotePath = "/fs/microsd/system/calibration/camera_intrinsics.json"
    status = upload(ftp,uav,localPath,remotePath)
    status = true

    Version History

    Introduced in R2026b