From 4e59416136e824e71477f171a02bdd156faf4b34 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 21 May 2024 14:53:38 +1200 Subject: [PATCH] Add FTP examples --- examples/ftp_download_file.py | 26 ++++++++++++++++++++++++++ examples/ftp_list_dir.py | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 examples/ftp_download_file.py create mode 100755 examples/ftp_list_dir.py diff --git a/examples/ftp_download_file.py b/examples/ftp_download_file.py new file mode 100755 index 00000000..f20a6909 --- /dev/null +++ b/examples/ftp_download_file.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import asyncio +from mavsdk import System + + +async def run(): + + drone = System(mavsdk_server_address="localhost", port=50051) + await drone.connect(system_address="serial:///dev/ttyACM0:57600") + + print("Waiting for drone to connect...") + async for state in drone.core.connection_state(): + if state.is_connected: + print(f"-- Connected to drone!") + break + + async for update in drone.ftp.download( + "/etc/extras/px4_io-v2_default.bin", ".", use_burst=False + ): + print(f"Got {update.bytes_transferred} of {update.total_bytes} bytes") + + +if __name__ == "__main__": + # Run the asyncio loop + asyncio.run(run()) diff --git a/examples/ftp_list_dir.py b/examples/ftp_list_dir.py new file mode 100755 index 00000000..0c8a85a3 --- /dev/null +++ b/examples/ftp_list_dir.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import asyncio +from mavsdk import System + + +async def run(): + + drone = System(mavsdk_server_address='localhost', port=50051) + await drone.connect(system_address="serial:///dev/ttyACM0:57600") + + print("Waiting for drone to connect...") + async for state in drone.core.connection_state(): + if state.is_connected: + print(f"-- Connected to drone!") + break + + print("directory list", await drone.ftp.list_directory("/")) + + +if __name__ == "__main__": + # Run the asyncio loop + asyncio.run(run())