Skip to content

swanbeck/lightweight_file_transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lightweight File Transfer

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.

Functions

The lightweight_file_transfer library only implements a small number of over-network file transfer functions.

  • send_file takes in an address of the form <IP_ADDRESS:PORT> for the recipient, a path to the file to send, connection_retry_time which specifies how long to wait between connection attempts, max_connection_retries which indicates how many connection attempts should be made, wait_for_acknowledgement which controls whether the sender will wait for an acknowledgement of receipt from the recipient, and acknowledgement_timeout that 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_directory takes in the same arguments as send_file but accepts a directory path dir rather than a path to a single file. send_directory will 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_files is used to receive files from a remote sender. It accepts an address at which the files should be received, a directory save_dir at which to save the files, a connection_timeout to timeout if no files are received, verify_checksum which 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), and send_acknowledgement to 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<()>

Python Bindings

lightweight_file_transfer_bindings uses maturin to compile the Rust library into a Python module. It can be built with

maturin build --release

from 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 lft

and 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.

About

A minimal over-network file transfer library written in Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages