The Rust library lightweight_file_transfer is a Rust crate. It can be built with Cargo and included in other Rust projects. Refer to the Rust documentation or the popular Rust Programming Language book for details of how to do this.
The lightweight_file_transfer library only implements a small number of over-network file transfer functions.
send_filetakes in anaddressof the form<IP_ADDRESS:PORT>for the recipient, apathto the file to send,connection_retry_timewhich specifies how long to wait between connection attempts,max_connection_retrieswhich indicates how many connection attempts should be made,wait_for_acknowledgementwhich controls whether the sender will wait for an acknowledgement of receipt from the recipient, andacknowledgement_timeoutthat indicates how long the sender will wait for an acknowledgement of receipt from the recipient, if told to wait.
pub fn send_file(
address: &str,
path: &str,
connection_retry_time: f32,
max_connection_retries: i32,
wait_for_acknowledgement: bool,
acknowledgement_timeout: f32,
) -> io::Result<()>send_directorytakes in the same arguments assend_filebut accepts a directory pathdirrather than a path to a single file.send_directorywill only send files in a directory, not any subdirectories or their contents.
pub fn send_directory(
address: &str,
dir: &str,
connection_retry_time: f32,
max_connection_retries: i32,
wait_for_acknowledgement: bool,
acknowledgement_timeout: f32,
) -> io::Result<()>receive_filesis used to receive files from a remote sender. It accepts anaddressat which the files should be received, a directorysave_dirat which to save the files, aconnection_timeoutto timeout if no files are received,verify_checksumwhich is used to make sure a sha256 hash for the file matches one sent by the sender (to ensure no data is lost in transmission), andsend_acknowledgementto tell the sender that the file(s) have been received.
pub fn receive_files(
address: &str,
save_dir: &str,
connection_timeout: f32,
verify_checksum: bool,
send_acknowledgement: bool,
) -> io::Result<()>lightweight_file_transfer_bindings uses maturin to compile the Rust library into a Python module. It can be built with
maturin build --releasefrom inside the project. This will produce a Python .whl file that can be installed with pip. You can then use it in your Python projects as
import lightweight_file_transfer as lftand use as
# server.py
lft.receive_files(
address='172.19.0.2:5000',
save_dir='/root/to',
send_acknowledgement=True,
)# client.py
lft.send_file(
address='172.19.0.2:5000',
path='/root/from/sample_file.gif',
wait_for_acknowledgement=True,
)for example. Some default arguments are implemented for the Python bindings, which are declared in the binding library file.