Receive files¶
To receive transfers, start a Client
with a download directory and an on_receive_request callback. The callback
chooses whether to accept the offer; accepted files are saved to the download
directory and can be reported through on_received.
Python¶
This accepts every incoming offer and saves its files in Downloads:
from pathlib import Path
from localsend import Client, IncomingTransfer, ReceivedFile
def accept_all(_transfer: IncomingTransfer) -> bool:
return True
def report_saved(received: ReceivedFile) -> None:
print(received.path)
with Client(
"My computer",
download_directory=Path.home() / "Downloads",
on_receive_request=accept_all,
on_received=report_saved,
):
input("Ready to receive files. Press Enter to stop. ")
Keep the process running, then select the Python client from a LocalSend
sender on the same LAN. To require a sender PIN, pass pin="123456" to
Client.
on_receive_request receives an
IncomingTransfer and can return
False to reject all files, a collection of file IDs to accept a subset, or
True/None to accept all files. The on_received callback receives a
ReceivedFile
after a file is saved. Use on_receive_failed to handle incomplete files
through ReceiveFailure. See the
Public API for callback behavior and configuration.