Skip to content

Commit 7a78033

Browse files
authored
Merge pull request #701 from mavlink/pr-example-list-dir
Add example how to list directory
2 parents da24c3c + 4e59416 commit 7a78033

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

examples/ftp_download_file.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
from mavsdk import System
5+
6+
7+
async def run():
8+
9+
drone = System(mavsdk_server_address="localhost", port=50051)
10+
await drone.connect(system_address="serial:///dev/ttyACM0:57600")
11+
12+
print("Waiting for drone to connect...")
13+
async for state in drone.core.connection_state():
14+
if state.is_connected:
15+
print(f"-- Connected to drone!")
16+
break
17+
18+
async for update in drone.ftp.download(
19+
"/etc/extras/px4_io-v2_default.bin", ".", use_burst=False
20+
):
21+
print(f"Got {update.bytes_transferred} of {update.total_bytes} bytes")
22+
23+
24+
if __name__ == "__main__":
25+
# Run the asyncio loop
26+
asyncio.run(run())

examples/ftp_list_dir.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
from mavsdk import System
5+
6+
7+
async def run():
8+
9+
drone = System(mavsdk_server_address='localhost', port=50051)
10+
await drone.connect(system_address="serial:///dev/ttyACM0:57600")
11+
12+
print("Waiting for drone to connect...")
13+
async for state in drone.core.connection_state():
14+
if state.is_connected:
15+
print(f"-- Connected to drone!")
16+
break
17+
18+
print("directory list", await drone.ftp.list_directory("/"))
19+
20+
21+
if __name__ == "__main__":
22+
# Run the asyncio loop
23+
asyncio.run(run())

0 commit comments

Comments
 (0)