[][src]Crate file_protocol

Kubos File Transfer Protocol


use file_protocol::*;
use std::time::Duration;

fn upload() -> Result<(), ProtocolError> {
    let config = FileProtocolConfig::new(Some("storage/dir".to_owned()), 1024, 5, 1, None, 2048);
    let f_protocol = FileProtocol::new("", "", config);

    let source_path = "client.txt";
    let target_path = "service.txt";

    // Copy file to upload to temp storage. Calculate the hash and chunk info
    let (hash, num_chunks, mode) = f_protocol.initialize_file(&source_path)?;

    // Generate channel id
    let channel_id = f_protocol.generate_channel()?;

    // Tell our destination the hash and number of chunks to expect
    f_protocol.send_metadata(channel_id, &hash, num_chunks)?;

    // Send export command for file
    f_protocol.send_export(channel_id, &hash, &target_path, mode)?;

    // Start the engine to send the file data chunks
    Ok(f_protocol.message_engine(|d| f_protocol.recv(Some(d)), Duration::from_millis(10), &State::Transmitting)?)
extern crate file_protocol;

use file_protocol::*;
use std::time::Duration;

fn download() -> Result<(), ProtocolError> {
    let config = FileProtocolConfig::new(None, 1024, 5, 1, None, 2048);
    let f_protocol = FileProtocol::new("", "", config);

    let channel_id = f_protocol.generate_channel()?;
    let source_path = "service.txt";
    let target_path = "client.txt";

    // Send our file request to the remote addr and verify that it's
    // going to be able to send it
    f_protocol.send_import(channel_id, source_path)?;

    // Wait for the request reply
    let reply = match f_protocol.recv(None) {
        Ok(message) => message,
        Err(error) => return Err(error)

    let state = f_protocol.process_message(
        &State::StartReceive {
            path: target_path.to_string(),

    Ok(f_protocol.message_engine(|d| f_protocol.recv(Some(d)), Duration::from_millis(10), &state)?)


pub use crate::protocol::Protocol as FileProtocol;
pub use crate::protocol::ProtocolConfig as FileProtocolConfig;
pub use crate::protocol::State;



File transfer protocol module



File protocol message types


Errors which occur when using FileProtocol



Parse out just the channel ID from a message