diff --git a/libraries/GCS_MAVLink/GCS_FTP.cpp b/libraries/GCS_MAVLink/GCS_FTP.cpp index 53ceca24ea2c0..3225688104b3b 100644 --- a/libraries/GCS_MAVLink/GCS_FTP.cpp +++ b/libraries/GCS_MAVLink/GCS_FTP.cpp @@ -624,6 +624,12 @@ void GCS_MAVLINK::ftp_list_dir(struct pending_ftp &request, struct pending_ftp & request.data[sizeof(request.data) - 1] = 0; // ensure the path is null terminated + // Strip trailing / + const size_t dir_len = strlen((char *)request.data); + if ((dir_len > 1) && (request.data[dir_len - 1] == '/')) { + request.data[dir_len - 1] = 0; + } + // open the dir auto *dir = AP::FS().opendir((char *)request.data); if (dir == nullptr) {