# File transfer MAVSDK: Protocol Error

**URL:** <https://discuss.px4.io/t/file-transfer-mavsdk-protocol-error/27917>\
**Category:** MAVSDK\
**Created:** [June 15, 2022, 1:44pm UTC](https://discuss.px4.io/t/file-transfer-mavsdk-protocol-error/27917 "2022-06-15T13:44:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rinto](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rinto](https://discuss.px4.io/u/rinto)\
**Post date:** [June 15, 2022, 1:44pm UTC](https://discuss.px4.io/t/file-transfer-mavsdk-protocol-error/27917/1 "2022-06-15T13:44:05Z")

</div>

Hi,

My setup is as follows;

Cube orange connected to companion computer (GPS2 port to USB/serial adpater). GPS2 port is configured as MAVLink port with a baudrate of 115200 and mav forwarding is on.

Additionally I have a herelink control system connected. I am usb tethering the herelink ground unit to a second computer.

I want to send files from the companion computer to the second computer over the mavlink network. I’m currently setting up an FTP server using:

```auto
int main(int argc, char** argv)
{
    if (argc != 4) {
        usage(argv[0]);
        return 1;
    }

    Mavsdk mavsdk;
    Mavsdk::Configuration configuration(Mavsdk::Configuration::UsageType::CompanionComputer);
    mavsdk.set_configuration(configuration);
    ConnectionResult connection_result = mavsdk.add_any_connection("udp://192.168.42.129:14552");
    if (connection_result != ConnectionResult::Success) {
        std::cerr << "Error setting up Mavlink FTP server.\n";
        return 1;
    }

    auto system_cc = mavsdk.systems().at(0);

    auto ftp_server = Ftp{system_cc};
    ftp_server.set_root_directory(argv[3]);

    std::cout << "Mavlink FTP server running.\n"
              << '\n'
              << "Remote: " << argv[1] << ":" << argv[2] << '\n'
              << "Component ID: " << static_cast<int>(ftp_server.get_our_compid()) << '\n';

    while (true) {
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    return 0;
}

```

I set up the client (connected to herelink) as follows:

```auto
    Mavsdk mavsdk;
    ConnectionResult connection_result = mavsdk.add_any_connection(argv[1]);

    if (connection_result != ConnectionResult::Success) {
        std::cerr << "Connection failed: " << connection_result << '\n';
        return 1;
    }

    auto system = get_system(mavsdk);
    if (!system) {
        return 1;
    }

    // Instantiate plugins.

    auto ftp = Ftp{system};
    try {
        ftp.set_target_compid(std::stoi(argv[2]));
    } catch (...) {
        std::cerr << "Invalid argument: " << argv[2] << '\n';
        return 1;
    }

    Ftp::Result res;
    res = reset_server(ftp);
    if (res != Ftp::Result::Success) {
        std::cerr << "Reset server error: " << res << '\n';
        return 1;
    }

```

Basically the basic mavsdk example, but changed the connection lines to my setup.

I’m stuck at the following:  
I can create a directory (although I get the error “Protocol Error”), but I cannot upload/download any files. Output for downloading file from client:

```auto
Download file: ftp_server.cpp to .
[03:41:47|Debug] Component Camera 1 (100) added. (system_impl.cpp:377)
[03:41:47|Warn] Response timeout. Retry: 1 (mavlink_ftp.cpp:908)
[03:41:48|Warn] Response timeout. Retry: 2 (mavlink_ftp.cpp:908)
[03:41:48|Warn] Response timeout. Retry: 3 (mavlink_ftp.cpp:908)
[03:41:48|Warn] Response timeout. Retry: 4 (mavlink_ftp.cpp:908)
File download error: File Does Not Exist

```

Output of server:

```auto
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Info] OPC:CMD_OPEN_FILE_RO (mavlink_ftp.cpp:100)
[03:41:47|Info] OPC:CMD_OPEN_FILE_RO (mavlink_ftp.cpp:100)
[03:41:47|Warn] FTP: Open failed - file not found (mavlink_ftp.cpp:1062)
[03:41:47|Info] OPC:CMD_OPEN_FILE_RO (mavlink_ftp.cpp:100)
[03:41:47|Warn] FTP: Open failed - file not found (mavlink_ftp.cpp:1062)
[03:41:47|Info] OPC:CMD_OPEN_FILE_RO (mavlink_ftp.cpp:100)
[03:41:47|Warn] FTP: Open failed - file not found (mavlink_ftp.cpp:1062)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:47|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Wrong sequence - resend last response (mavlink_ftp.cpp:73)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)
[03:41:48|Warn] Received NAK without active operation (mavlink_ftp.cpp:347)

```

Root directory of server is set to current directory, thus the file does exists. Can someone help me solve this?

---

<div class="post-metadata">

**Author:** ![rinto](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rinto](https://discuss.px4.io/u/rinto)\
**Post date:** [June 15, 2022, 2:19pm UTC](https://discuss.px4.io/t/file-transfer-mavsdk-protocol-error/27917/2 "2022-06-15T14:19:05Z")

</div>

Another thing: If I try to list the items in a directory, I get the output from the server:

```auto
[04:15:00|Warn] FTP: invalid path /home/mbi/Desktop/alternative-drone/no-commit/MAVSDK/examples/ftp_server (mavlink_ftp.cpp:979)

```

The path exists and looks valid to me.

---

<div class="post-metadata">

**Author:** ![rinto](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rinto](https://discuss.px4.io/u/rinto)\
**Post date:** [June 17, 2022, 11:49am UTC](https://discuss.px4.io/t/file-transfer-mavsdk-protocol-error/27917/3 "2022-06-17T11:49:20Z")

</div>

Okay, the problem is different than expected. The problem is that uploading works fine, but downloading and listing directories fails. This sound like a permission error to me (although I enabled read, write and execute permissions to the relevant folder). I will open up a new topic for this.
